Question

I'm running Wordpress with: Nginx + PHP-FPM + APC + W3 Total Cache + PageSpeed. After 3 days researching and configuring, I succeeded to configure.

Running "top" and hitting some cached pages, it shows:

PID   USER      PR  NI  VIRT  RES  SHR S %CPU %MEM    TIME+  COMMAND
13387 nginx     20   0  472m  11m 4664 S 12.3  2.0   0:46.55 nginx
17577 nginx     20   0  443m  47m  29m S  0.7  8.0   0:42.88 php-fpm
17591 nginx     20   0  438m  43m  29m S  0.7  7.2   0:42.59 php-fpm
1486  mysql     20   0  851m  21m 4832 S  0.3  3.7   1:24.71 mysqld
17907 nginx     20   0  438m  48m  34m S  0.3  8.1   0:36.78 php-fpm
18065 nginx     20   0  442m  47m  29m S  0.3  8.0   0:33.49 php-fpm
18543 nginx     20   0  445m  63m  42m S  0.3 10.6   0:22.94 php-fpm
21125 root      20   0 15012 1148  868 R  0.3  0.2   0:00.86 top
1     root      20   0 19356 1388 1136 S  0.0  0.2   0:00.74 init

1) Why every request is being processed by PHP-PFM? Shouldn't W3 Total Cache supposed to prevent the request from been processed by PHP-FPM?

I know that my page is being cached because every page return in the end of HTML:

<!-- Performance optimized by W3 Total Cache. Learn more: http://www.w3-edge.com/wordpress-plugins/
Page Caching using disk: enhanced

2) If I install Varnish in front of Nginx, will it stop the request from being processed by PHP-FPM? (Performance will increase? I'm using a Micro Ec2, Ram = 613MB)

PS: The response header is returning "Cache-Control: max-age=0, no-cache" from server. I don't know if this influence W3 Caching.

My specs:

  • Amazon Micro EC2
  • Linux version 3.4.48-45.46.amzn1.x86_64 Red Hat 4.6.3-2 (I think it's based on CentOS 5)
  • PHP 5.3.26 (fpm-fcgi)
Was it helpful?

Solution 2

I installed Varnish in front of my server, but again, it was being processed by PHP-FPM.

The problem was the lacking of slash at the end of the URL.

In Wordpress, a page is a directory, so it respond as www.mysite.com/page1/.

The point is when you hit www.mysite.com/page1 (without the slash), Nginx have to redirect to www.mysite.com/page1/ (with slash), and by doing this, it uses PHP-FPM.

After putting the slash at the end of all links in my site, the redirect was not done, and all of my page was not processed by PHP-FPM.

OTHER TIPS

I'm not aware of how this w3 total cache works, but let me state to you some facts,

first of all on the nginx level, any php page must hit the php engine, because that's probably what your try_files tells the nginx to do, if w3 total cache has some sort of html cache of the pages, then without some changes to nginx config you will still hit the php even if the cache existed. And if the cache is not really in a form of html then probably the php engine checks for the existence of the page then decides whether to rebuild the page or serve the cached one instead, so you definitely need php to run, the difference is that it won't hit the database and it won't do any processing, just serving the cached page instead.

second question, varnish, yes varnish would actually be good, it would spare you the need of a cache plugin, but then you need to make sure that wordpress knows when to ask varnish to purge the cached pages, the structure of the server would be user -> varnish -> nginx -> php, if varnish has a cached page or assets (css,js,etc) it would serve it directly without passing the request to nginx, I've tried it on a website and the response times of a cached page definitely improved, even when i did a ctrl+f5 to request the whole page without cache it still returned very fast as if the page was just a plain html page.
You'll still need to mess around with the varnish config, or at least that's what i did, because it needs a little bit of learning, but so far all I did was some copy and pasting from blogs and stuff and it worked just fine with me.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top