-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprewarm.php
56 lines (48 loc) · 1.41 KB
/
prewarm.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
<?php
/**
* pre-warm the opcache with all files in the project,
* using Symfony's Finder.
*
* This can be simplified a lot, if this PR gets merged:
* https://github.com/php/php-src/pull/16862
* As currently, `opcache_compile_file(...)` is loading
* functions into the global context, which requires us
* to omit files that are already loaded, or we get
* "function already exists" errors.
*/
/**
* To prevent "function already exists" errors,
* as mentioned above:
*
* Trick composer into thinking we've already
* any helper scripts, usually loaded automatically
* when the auto-loader is registered.
*/
$filesToLoad = require __DIR__ . '/vendor/composer/autoload_files.php';
// Prevent composer autoloading files...
foreach ($filesToLoad as $fileIdentifier => $file) {
$GLOBALS['__composer_autoload_files'][$fileIdentifier] = true;
}
/**
* -----------
*/
require __DIR__ . '/vendor/autoload.php';
$finder = (new Symfony\Component\Finder\Finder())
->files()
->name('/\.php$/')
->ignoreDotFiles(false)
->ignoreVCSIgnored(false)
->exclude([
'vendor/composer',
])
->notPath([
// e.g. 'fuel/core/bootstrap.php',
])
->in(__DIR__);
foreach($finder as $file) {
$filepath = $file->getRealPath();
echo "Compiling file " . $file->getRelativePathname() . " ... " .
(
opcache_compile_file($filepath) ? 'OK' : 'FAIL'
) . "\n";
}