Created
October 9, 2017 10:03
-
-
Save klimslim/ce8f727b3b419badce243bf5a74389b6 to your computer and use it in GitHub Desktop.
Zend opcache warmup
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$start = microtime(true); | |
$files = 0; | |
$errors = 0; | |
foreach (['/home/httpd/html/'] as $path) { | |
// Get the realpath and check it's valid | |
$path = realpath($path); | |
if (!$path) { | |
continue; | |
} | |
// Create a directory iterator | |
$dir = new RecursiveDirectoryIterator($path); | |
// Create a recursive iterator | |
$iterator = new RecursiveIteratorIterator($dir); | |
$filters = function($file) { | |
// Check the extension | |
$ext = $file->getExtension(); | |
if (!($ext == 'php')) { | |
return false; | |
} | |
return true; | |
}; | |
// Filter the iterator using our custom filter iterator | |
$filter = new CallbackFilterIterator($iterator, $filters); | |
// Iterate over the files that match | |
$return = 0; | |
foreach ($filter as $file) { | |
$realPath = $file->getRealPath(); | |
if ($return == 0) { | |
// Increment our counter | |
$files++; | |
// Cache the file with Zend OpCache | |
if(opcache_compile_file($realPath)) { | |
if(!opcache_is_script_cached($realPath)) { | |
echo $realPath.' was not cached <br>'.PHP_EOL; | |
} | |
} | |
} else { | |
// Increment our error counter | |
$errors++; | |
} | |
} | |
} | |
time(true); | |
// Display results | |
echo "Cached $files files in " .($end - $start). " seconds" . PHP_EOL; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment