Forum Moderators: phranque

Message Too Old, No Replies

Opcache

         

faceman

7:35 pm on Nov 21, 2016 (gmt 0)

10+ Year Member Top Contributors Of The Month



What is the correct way to use this with php-fpm? I mean all the basic details (to tell my host). This is basically whats happened.

We activated it with php-fpm on the cgi php handler but opcache does not get going. It is stuck on 2 cache hits and 58 misses.

My host suggested change to dso php handler. So we did that and opcache appears up and running, it has lots of cache hits but it broke the site, those who visit are now struggling to stay logged in and are seeing pages that are not updated (unless they refresh the page, then they are logged in and see the updated list, if that makes sense). The problem is this happens all the time, whenever logging in it just delivers cached pages that are not up to date (again unless refreshed)

Changing back to php-fpm / cgi fixes that issue. But it doesn't explain why the other setting broke the site nor help me set up opcache.

Explain to me as if I was 5 because my server knowledge isn't there and my hosts are just pointing to the web developer and they are pointing me to the hosts.

lucy24

6:19 pm on Nov 23, 2016 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



faceman, we aren't ignoring you. Yours is one of the rare questions that requires someone who actually speaks Apache (as opposed to just whipping up a suitable Regular Expression), so sit tight.

robzilla

7:58 pm on Nov 23, 2016 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Anything in your error logs? Did you check your file permissions? If people can't stay logged in, that often indicates a problem with PHP's session files, like Apache/php-fpm not having the rights to write to the session directory.

Note that an opcode cache does not cache the output of a webpage, it only caches the run-time conversion of PHP code to machine language. So it doesn't make much sense that an opcode cache would cause users to have to refresh a page to get the latest content; that's usually more indicative of a problem with the browser cache (are you setting cache headers for your dynamic content?).

"2 cache hits and 58 misses" is not unusual in the beginning, as the cache still needs to be primed. Once the most-visited pages are cached, you should start seeing more hits.

faceman

8:13 pm on Nov 23, 2016 (gmt 0)

10+ Year Member Top Contributors Of The Month



People can't stay logged in only when opcache is enabled though - well they actually are logged in, the browser is just displaying the cached page. The file permissions are all above board as far as I'm aware.

I have expires in the htaccess file, could this cause an issue? This is what I have incase you wondered:

FileETag None
<IfModule mod_deflate.c>
<filesMatch ".(css|js|x?html?|php)$">
SetOutputFilter DEFLATE
</filesMatch>
</IfModule>
<IfModule mod_expires.c>
ExpiresActive On
ExpiresDefault "now plus 1 week"
ExpiresByType image/gif "access plus 1 month"
ExpiresByType image/jpg "access plus 1 month"
ExpiresByType image/jpeg "access plus 1 year"
ExpiresByType image/png "access plus 1 month"
ExpiresByType text/css "access plus 1 month"
ExpiresByType text/javascript "access plus 1 week"
ExpiresByType application/javascript "access plus 1 week"
ExpiresByType application/x-javascript "access plus 1 week"
ExpiresByType application/x-shockwave-flash "access plus 1 week"
ExpiresByType video/x-flv "access plus 1 week"
ExpiresByType application/pdf "access plus 1 week"
ExpiresByType text/xml "access plus 1 month"
ExpiresByType image/x-icon "access plus 1 year"
ExpiresByType application/font-woff "access plus 1 month"
ExpiresByType application/x-font-woff "access plus 1 month"
ExpiresByType font/woff "access plus 1 month"
ExpiresByType application/font-woff2 "access plus 1 year"
ExpiresByType application/vnd.ms-fontobject "access plus 1 month"
ExpiresByType application/x-font-ttf "access plus 1 month"
ExpiresByType font/opentype "access plus 1 month"
ExpiresByType image/svg+xml "access plus 1 month"
</IfModule>


2 cache hits and 58 misses never once changed though, only when I changed to dso from cgi and then it was into 100000+ hits within an hour

robzilla

9:45 am on Nov 24, 2016 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



ExpiresDefault "now plus 1 week" 

I'm not too familiar with Apache's inner workings, but I would assume this configuration will send a header to users' browsers to cache your dynamic pages (as well as other types of content not specified) for up to 1 week, and users would indeed have to refresh the page to get a fresh copy. It may also explain why after POSTing their credentials to log in, users don't seem to be logged in, as the browser may show the previous cached version of the page where they hadn't logged in yet. Whether the credentials are actually sent to the server depends on your implementation, but it sounds like this does happen, as you mention that users are logged in once they refresh the page. This has nothing to do with the opcache, though.

You can check the headers using the Developer Tools ("Network" tab) on most modern web browsers, or use a tool like Webpagetest.org.

Or simply try adding:
ExpiresByType text/html "access"

faceman

11:14 am on Nov 24, 2016 (gmt 0)

10+ Year Member Top Contributors Of The Month



I removed the entire part in htaccess and it works correctly now. Thanks for your help! Although now I don't have a working image expires ha

robzilla

12:32 pm on Nov 24, 2016 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



So put them back :-) Just add the one for text/html, and optionally remove the ExpiresDefault setting, or remove all but the text/html one and set ExpiresDefault to access + 1 month. Whatever works best for you.

faceman

1:36 pm on Nov 24, 2016 (gmt 0)

10+ Year Member Top Contributors Of The Month



When I put them back it goes wrong, so there is a part of it that is causing the issue. Do I need the expiresdefault setting, if it is that that's the problem?

Also my pages are .php (it is an IPS4 forum), would the text/html setting still have effect?

robzilla

3:50 pm on Nov 24, 2016 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



You don't need the ExpiresDefault setting if you manually set expiry headers by content-type, e.g. text/html, text/css, image/jpg, etc. Try removing ExpiresDefault and adding ExpiresByType text/html "access".

Also my pages are .php (it is an IPS4 forum), would the text/html setting still have effect?

Yes, your PHP scripts output content of the type text/html, i.e. they're webpages. The file extension is largely irrelevant.

faceman

4:11 pm on Nov 24, 2016 (gmt 0)

10+ Year Member Top Contributors Of The Month



Thanks for the explanation. It does seem to work right after making that change. Hopefully opcache still works as it should though after adding that text/html part as that must have been left out for a reason.

robzilla

11:50 pm on Nov 24, 2016 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Opcode caching is unrelated to browser caching, i.e. the expiry headers you're setting via .htaccess. They don't interact and so they won't interfere either. Glad you got it working now, though.