Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Will the PHP 5.5 opcache be shared across processes with FastCGI (mod_fcgi)?

Tags:

php

fastcgi

My website is running on PHP 5.5 with FastCGI (mod_fcgi). I'm aware that other opcache types (like APC) doesn't work well as memory is not shared between php-cgi processes (here).

I'm using PHP 5.5 built-in OPcache. Is the memory shared between processes or this is exactly the same problem of APC/Xcache with mod_fcgi?

Is there any way to test it?

like image 758
gremo Avatar asked May 03 '14 10:05

gremo


People also ask

How PHP OPcache works?

OPcache is a caching engine built into PHP. When enabled, it dramatically increases the performance of websites that utilize PHP. From php.net: OPcache improves PHP performance by storing precompiled script bytecode in shared memory, thereby removing the need for PHP to load and parse scripts on each request.

How to enable OPcache in PHP?

OPcache can only be compiled as a shared extension. If you have disabled the building of default extensions with --disable-all, you must compile PHP with the --enable-opcache option for OPcache to be available. Once compiled, you can use the zend_extension configuration directive to load the OPcache extension into PHP.

How do you flush OPcache?

To clear the Opcache on CLI, just restart your PHP command. It's usually as simple as CTRL+C to abort the command and start it again.


1 Answers

I have never understood why this was even entertained as a possibility, it is not a realistic possibility:

Both APC and Opcache have several forms of shared memory, their defaults and the most suitable kind is mmap'd memory, but for all kinds of strange reasons they need to support inferior kinds, none of these inferior kinds leave a possibility (even an unrealistic one) for this to work.

When it comes to mmap...

APC

If you do not provide a file mask APC uses anonymous shared mapping, you cannot share this across distinct process boundaries, not possible.

If you do provide a file mask, APC uses unsynchronized shared mapping, it doesn't make sense to try and share that across distinct process boundaries since it will nearly always contain a corrupted shadow of the mapped memory, that's the nature of unsynchronized.

Opcache

Doesn't provide you with any of the non-options that APC tried to provide, all mapping is done anonymously.

Solution

Use a sane webserver such as nginx/lighthttpd, and use fpm, included with PHP.

FPM's process model allows the child processes it forks to have a common cache, problem solved, applicable to both APC and Opcache.

like image 184
Joe Watkins Avatar answered Oct 11 '22 15:10

Joe Watkins