I'm using PHP-FPM 5.6 version.
php -v shows there's OPcache in place.
I have a PHP script that's accepting parameters and giving me same 2.2k
HTML output all the time.
The script execution does not involve any connectivity to MySQL.
In Chrome Developer Tools, I'm seeing an execution time of 900ms
.
I find that this is relatively slow.
I would like to shorten this execution time.
Given that OPcache is in place with this version of PHP, can I use it to cache the result of my PHP script execution for a faster response time?
Or if there's an alternative approach?
Any configuration to be tweaked in php.ini
, /etc/php.d/10-opcache.ini
or /etc/php-fpm.d/www.conf
?
And how do I purge the cached result when needed?
I know this doesn't directly answer your question, but it might be useful. The way to measure execution time could involve these two functions:
function getMicroTime()
// return time in whole seconds with microseconds
{
return microtime(TRUE);
}
function getUserTime()
// this clock only runs when we have CPU cycles, so it runs slower that the normal clock
// use this to accurately time the excution time of scripts instead of the above function
{
$usage = getrusage();
return $usage["ru_utime.tv_sec"]+0.000001*$usage["ru_utime.tv_usec"];
}
At the beginning of your script you store the start times:
$startMicroTime = getMicroTime();
$startUserTime = getUserTime();
So that at the end you can echo the execution time:
echo 'Full time = '.round(1000*(getMicroTime()-$startMicroTime),2).' ms<br>';
echo 'User time = '.round(1000*(getUserTime()-$startUserTime),2).' ms<br>';
Again, this doesn't answer your question, but it could be useful. Ok, to make this a valid answer, have a read here:
https://www.addedbytes.com/articles/for-beginners/output-caching-for-beginners/