# PHP-FPM no cache

**URL:** <https://www.ruby-forum.com/t/php-fpm-no-cache/209044>\
**Category:** NGINX\
**Created:** [July 4, 2011, 9:11am UTC](https://www.ruby-forum.com/t/php-fpm-no-cache/209044 "2011-07-04T09:11:52Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![luislavena](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/0ea827/32.png) [@luislavena](https://www.ruby-forum.com/u/luislavena)\
**Post date:** [July 4, 2011, 9:11am UTC](https://www.ruby-forum.com/t/php-fpm-no-cache/209044/1 "2011-07-04T09:11:52Z")

</div>

Hello,

I’ve enabled caching on php scripts as below but it looks like the  
server is not caching at all:

http {  
fastcgi\_cache\_path /tmp/cache levels=1:2  
keys\_zone=tmp:10m  
inactive=5m;

server {  
location / {  
…  
fastcgi\_cache tmp;  
fastcgi\_cache\_valid any 1h;  
fastcgi\_cache\_min\_uses 1;  
…  
}  
}  
}

- but the caching directory is totally empty (nginx has write privileges  
as it was created by nginx itself during reload)
- I haven’t noticed any performance improvements by running apache  
benchmark from different machine

Logs:

2011/07/04 07:53:59 [notice] 1082#0: start cache manager process 1088  
2011/07/04 07:53:59 [notice] 1082#0: start cache loader process 1089  
2011/07/04 07:54:59 [notice] 1089#0: http file cache: /tmp/cache 0.000M,  
bsize: 4096  
2011/07/04 07:54:59 [notice] 1082#0: signal 17 (SIGCHLD) received  
2011/07/04 07:54:59 [notice] 1082#0: cache loader process 1089 exited  
with code 0  
2011/07/04 07:54:59 [notice] 1082#0: signal 29 (SIGIO) received

OS: CentOS 5.6  
Nginx version: nginx/0.8.54

Could you help me to solve this please.

Posted at Nginx Forum:

> **[PHP-FPM no cache](https://forum.nginx.org/read.php?2,211926,211926#msg-211926)**
>
> Hello, I've enabled caching on php scripts as below but it looks like the server is not caching at all: http { fastcgi\_cache\_path /tmp/cache levels=1:2 keys\_zone=tmp:10m inactive=5m;

---

<div class="post-metadata">

**Author:** ![HTF](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/b19c9b/32.png) [@HTF](https://www.ruby-forum.com/u/HTF)\
**Post date:** [July 4, 2011, 11:00am UTC](https://www.ruby-forum.com/t/php-fpm-no-cache/209044/2 "2011-07-04T11:00:39Z")

</div>

Hello!

On Mon, Jul 04, 2011 at 02:11:11AM -0500, HTF wrote:

> server {
> 
> - but the caching directory is totally empty (nginx has write privileges  
> as it was created by nginx itself during reload)
> - I haven’t noticed any performance improvements by running apache  
> benchmark from different machine

Check your php responses, most likely they disable cache: nginx  
honors Cache-Control, Expires headers, and additionally it will  
disable cache if it sees Set-Cookie header in response. This  
behaviour may be overwritten if desired with  
fastcgi\_cache\_ignore\_headers directive, see here:

> **[GitHub - nginxinc/nginx-wiki: ARCHIVED -- Source for the now archived NGINX Wiki...](https://github.com/nginxinc/nginx-wiki)**
>
> ARCHIVED -- Source for the now archived NGINX Wiki section of https://www.nginx.com

Note though that it’s not generally safe as it may cause private  
pages (and/or cookies) to be cached and returned to other clients.  
Handle with care.

Maxim D.

---

<div class="post-metadata">

**Author:** ![HTF](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/b19c9b/32.png) [@HTF](https://www.ruby-forum.com/u/HTF)\
**Post date:** [July 5, 2011, 8:49am UTC](https://www.ruby-forum.com/t/php-fpm-no-cache/209044/3 "2011-07-05T08:49:33Z")

</div>

Thank you.

I added the following directives in my config file  
…  
fastcgi\_ignore\_headers Expires Cache-Control;  
fastcgi\_pass\_header Set-Cookie;  
…

- and the caching is working now but I still have few questions:

1. “Note though that it’s not generally safe as it may cause private  
pages (and/or cookies) to be cached and returned to other clients.  
Handle with care.”

- so should I use the caching in my case if it’s working only with the  
‘ignore’ option only. Could you tell me when this may happen (“private  
pages and/or cookies to be cached”), could you provide some examples  
please.

1. Content of my website is not changing often what is the recommended  
validation time - hours, days?

2. I have contact form where little message pop after the message is  
submitted. With cache enabled this window appears on a different menu  
tab. How to avoid this, should I exclude contact page from caching or is  
there a better way to do it?

3. When I run Apache benchmark (ab -c 100 -n 5 http:domain.com/) the  
website is not cached unless I visit it through web browser then AB also  
use cache. Is there any explanation fort this behaviour?

Sorry for so many questions but I try to understand this better.

Thank you for your help once again

Regards

Posted at Nginx Forum:

> **[Re: PHP-FPM no cache](https://forum.nginx.org/read.php?2,211926,211948#msg-211948)**
>
> Hello, I've enabled caching on php scripts as below but it looks like the server is not caching at all: http { fastcgi\_cache\_path /tmp/cache levels=1:2 keys\_zone=tmp:10m inactive=5m;

---

<div class="post-metadata">

**Author:** ![HTF](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/b19c9b/32.png) [@HTF](https://www.ruby-forum.com/u/HTF)\
**Post date:** [July 5, 2011, 11:22am UTC](https://www.ruby-forum.com/t/php-fpm-no-cache/209044/4 "2011-07-05T11:22:19Z")

</div>

Hello!

On Tue, Jul 05, 2011 at 02:48:57AM -0400, HTF wrote:

> I added the following directives in my config file  
> …  
> fastcgi\_ignore\_headers Expires Cache-Control;  
> fastcgi\_pass\_header Set-Cookie;

You don’t need “fastcgi\_pass\_header Set-Cookie;” in 0.8.54, it’s  
passed by default.

> - and the caching is working now but I still have few questions:
> 
> 1. “Note though that it’s not generally safe as it may cause private  
> pages (and/or cookies) to be cached and returned to other clients.  
> Handle with care.”
> 
> - so should I use the caching in my case if it’s working only with the  
> ‘ignore’ option only. Could you tell me when this may happen (“private  
> pages and/or cookies to be cached”), could you provide some examples  
> please.

Consider your backend uses “Cache-Control” for reason, e.g. it  
presents personalized pages for each authenticated user. If you  
ignore Cache-Control and don’t have some user id added to  
fastcgi\_cache\_key - all of your users will see the same cached  
page.

That’s why recommended aproach is to fix backend to return correct  
Cache-Control which allows caching for pages which may be cached  
and vice versa.

> 1. Content of my website is not changing often what is the recommended  
> validation time - hours, days?

Up to you. This mostly depends on how quickly you need changes to  
be shown once they finally happen.

> 1. I have contact form where little message pop after the message is  
> submitted. With cache enabled this window appears on a different menu  
> tab. How to avoid this, should I exclude contact page from caching or is  
> there a better way to do it?

This looks like a result of problems discussed in (1).

> 1. When I run Apache benchmark (ab -c 100 -n 5 http:domain.com/) the  
> website is not cached unless I visit it through web browser then AB also  
> use cache. Is there any explanation fort this behaviour?

Just a wild guess: your backend returns some visitor tracking  
cookie for ab as it doesn’t have one, and hence nginx doesn’t  
cache responses to ab.

Maxim D.

---

<div class="post-metadata">

**Author:** ![HTF](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/b19c9b/32.png) [@HTF](https://www.ruby-forum.com/u/HTF)\
**Post date:** [July 6, 2011, 8:35am UTC](https://www.ruby-forum.com/t/php-fpm-no-cache/209044/5 "2011-07-06T08:35:21Z")

</div>

Thanks for help, really helpful.

Posted at Nginx Forum:

> **[Re: PHP-FPM no cache](https://forum.nginx.org/read.php?2,211926,211982#msg-211982)**
>
> Hello, I've enabled caching on php scripts as below but it looks like the server is not caching at all: http { fastcgi\_cache\_path /tmp/cache levels=1:2 keys\_zone=tmp:10m inactive=5m;
