Inconsistent PHP 7 Opcache Stats: Cloudflare vs. Direct


#1

I enabled Cloudflare Flexible SSL on my websites in 2017 and in parallel researched and installed Let’s Encrypt. I had a few tertiary subdomains for testing which bypassed Cloudflare - this allowed me to easily test Let’s Encrypt. I never got around to switching to Cloudflare Full SSL. I recently upgraded my webserver from PHP 5.3 with APC to PHP 7 with opcache support. I noticed that the opcache statistics were different for the primary subdomain that was fronted by Cloudflare and the test subdomain which was an alias of a.b.com. In both cases, I was using https.

I eliminated Cloudflare and browser caching, which left me without a clue as to the cause of the difference. Cloudflare was involved somehow - if I disabled Cloudflare on the primary subdomain, the opcache statistics were the same. While looking for ways to clear opcache, I stumbled on https://ma.ttias.be/how-to-clear-php-opcache/ which showed how to create ‘flush_cache.php’ and said “It’s important that you call that URL in the same way you would reach your website, either via a HTTP or HTTPS URL.” It appears that PHP 7 maintains a separate opcache for regular and secure HTTP traffic. Although I used Secure HTTP for both the primary and test subdomains, Cloudflare Flexible SSL was communicating with my webserver using the http protocol. So, if you see inconsistent opcache results, you may actually be running separate opcache instances.

Regards, Norbert