Cache opcache status to reduce function_exists() calls

This commit is contained in:
Kijin Sung 2017-12-09 01:40:04 +09:00
parent b25ce87ae5
commit 0023a9cc1a

View file

@ -17,6 +17,11 @@ class Storage
*/ */
protected static $_umask; protected static $_umask;
/**
* Cache the opcache status here.
*/
protected static $_opcache;
/** /**
* Check if a path really exists. * Check if a path really exists.
* *
@ -297,7 +302,11 @@ class Storage
$filename = $original_filename; $filename = $original_filename;
} }
if (function_exists('opcache_invalidate') && substr($filename, -4) === '.php') if (self::$_opcache === null)
{
self::$_opcache = function_exists('opcache_invalidate');
}
if (self::$_opcache && substr($filename, -4) === '.php')
{ {
@opcache_invalidate($filename, true); @opcache_invalidate($filename, true);
} }
@ -410,7 +419,11 @@ class Storage
$destination = $original_destination; $destination = $original_destination;
} }
if (function_exists('opcache_invalidate') && substr($destination, -4) === '.php') if (self::$_opcache === null)
{
self::$_opcache = function_exists('opcache_invalidate');
}
if (self::$_opcache && substr($destination, -4) === '.php')
{ {
@opcache_invalidate($destination, true); @opcache_invalidate($destination, true);
} }
@ -461,7 +474,11 @@ class Storage
@chmod($destination, 0666 & ~self::getUmask()); @chmod($destination, 0666 & ~self::getUmask());
} }
if (function_exists('opcache_invalidate')) if (self::$_opcache === null)
{
self::$_opcache = function_exists('opcache_invalidate');
}
if (self::$_opcache)
{ {
if (substr($source, -4) === '.php') if (substr($source, -4) === '.php')
{ {
@ -500,7 +517,11 @@ class Storage
trigger_error('Cannot delete file: ' . $filename, \E_USER_WARNING); trigger_error('Cannot delete file: ' . $filename, \E_USER_WARNING);
} }
if (function_exists('opcache_invalidate') && substr($filename, -4) === '.php') if (self::$_opcache === null)
{
self::$_opcache = function_exists('opcache_invalidate');
}
if (self::$_opcache && substr($filename, -4) === '.php')
{ {
@opcache_invalidate($filename, true); @opcache_invalidate($filename, true);
} }