Description
Request For Comments
Hi!
As we all know, php 7.x ships with opcache. It would be nice if the filesystem library invalidates the opcache files whenever there is an operation that changes the op code cached content.
I personaly don't like opcache_reset since AFAIK it resets the cache for all php instance (which can have multiple sites/application hosted), so probably the opcache_invalidate (and alternatives caching) could be a better alternative.
This process actually happens in joomla core restore part https://github.com/joomla/joomla-cms/blob/staging/administrator/components/com_joomlaupdate/restore.php#L8315 but AFAIK does exist in joomla as a whole.
Unless i'm missing something (which is probable ...) adding a method like this to the filesystem framework package and purging the opcache on php file overwrite would allow for a more agressive opcahing server config with joomla, and thus better joomla performance.
Example of more agressive opcaching:
opcache.validate_timestamps = 0 ; Default value "1" | 0 for no timestamp validation
opcache.revalidate_freq = 60 ; Default value "2" | 0 for always revalidate | x for seconds
opcache.revalidate_path = 0 ; Default value "0" | 1 for always revalidate
http://php.net/manual/en/opcache.configuration.php
So, something like this called at every changed php file, maybe could do the job:
public function purgeFileFromOpCodeCache(string $filePath)
{
if (function_exists('opcache_invalidate'))
{
return opcache_invalidate($filePath);
}
if (function_exists('apc_compile_file'))
{
return apc_compile_file($filePath);
}
if (function_exists('wincache_refresh_if_changed'))
{
return wincache_refresh_if_changed([$filePath]);
}
if (function_exists('xcache_asm'))
{
return (bool) xcache_asm($filePath);
}
return false;
}