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:
- What modules do I need?
- What modifications to do on nginx config?
- What if I need to use CSP(Content Security Policy) nonce(Then every page is dynamic)?
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!