0

Say that I am creating a news site on example.com, and now I have example.com/latest.php, this is a script that does a lot of query, and I want to improve performance. How can I configure php/nginx, so that it generates cache and when a visitor comes, the cache is sent, so s/he won't wait too long.
PS: On example.com/donotcache.php, I don't want it to be cached (user counting script), how to do it? Questionlist:

  1. What modules do I need?
  2. What modifications to do on nginx config?
  3. What if I need to use CSP(Content Security Policy) nonce(Then every page is dynamic)?
2
  • First thing you should do is to check your database structure and indexes. If you want to use CSP nonce, then you cannot cache in nginx. nginx caching configuration depends on your current configuration, so please add output of nginx -T to the question so the respective directives can be added. Commented Aug 27, 2021 at 7:05
  • you'd want to collect info on your load first before doing anything. trace and profile your web app first before deciding on what optimizations to do. Commented Aug 27, 2021 at 8:54

1 Answer 1

-1

You should be able to use the OPcache code within php itself to make sure you are not compiling php with each visitor hit to your site. Please be aware this will require a system memory allocation to hold cached compiled php. It can be much faster if your hit rate is high enough. If you have the memory to do it, you can even configure your MySQL query cache to hold query results. There is a trade off however, with how much memory things require and how much memory you have. Swapping will kill your performance. Poor performance will drive your site traffic away ... it's a delicate balancing act.

If you use the php packages from some repository somewhere, look for the OPcache module in php. If you're compiling it, make sure you enable OPcache at compile time. You shouldn't have to tell nginx anything about OPcache. Set your cache size in the system-level php.ini and you're ready to rock & roll!

1
  • 1
    Neither of it answers the question really, but let's touch on what you've said. PHP OPCache does not need memory per se, as in recent versions it introduces file-based OPcache. MySQL query cache, if you referring to the one in the MySQL server itself, is deprecated in not so recent versions of MySQL, enough to say, that in 8.0 it is not available at all. Finally, I think OP means to ask about full page cache. and it is done in NGINX (fastcgi cache) or Varnish, etc. Commented Aug 27, 2021 at 21:45

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.