Over the weekend I was testing turning on PHP's built-in opcache to see how it would affect Yioop's performance. Basically, opcache will cache in shared memory PHP scripts after they have been converted to bytecode. This means these scripts don't have to be reloaded and converted to bytecode on each request. The
opcache manual page didn't have specific instructions for osx, so I thought I'd briefly mention them here, since that is what I am running. On OS X, if you're running Yosemite or later, php opcache will be installed, you just need to enable it. There are a couple php.ini
files you could edit.
/etc/php.ini
or if you have the Server.app
/Library/Server/Web/Config/php/php.ini
If /etc/php.ini doesn't exist yet, there should be a file /etc/php.ini.default that you can copy to /etc/php.ini. I recommend editing /etc/php.ini since that location is more cross-platform. Within this file you want to tell php to land this extension by having the line:
zend_extension=opcache.so
other than that you add configuration setting either as described on the manual site or by tweaking them. Yioop seems to eat a little more memory than the basic configuration they had so I bumped up the cache setting for a few things to get:
realpath_cache_ttl = 120
zend_extension=opcache.so
opcache.memory_consumption = 256
opcache.interned_strings_buffer = 16
opcache.max_accelerated_files = 4000
opcache.validate_timestamps = 1
opcache.revalidate_freq = 0
opcache.fst_shutdown = 1
output_buffering=4096
implicit_flush = false;
Only the setting beginning with opcache above are directly opcache related, the other are some minor tweaks I threw in for good measure. Be sure to restart the web server after making any changes. As an example of the improvement, a blank query before using opcache took about .3 seconds (i.e., a query that should be doing nothing, so the time was just reading and parsing PHP).
After turning on opcache the time was reduced to 0.03 seconds.