-
Notifications
You must be signed in to change notification settings - Fork 120
/
Copy pathOpcacheClass.php
executable file
·79 lines (67 loc) · 1.79 KB
/
OpcacheClass.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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
<?php
namespace Appstract\Opcache;
use Symfony\Component\Finder\Finder;
/**
* Class OpcacheClass.
*/
class OpcacheClass
{
/**
* Clear OPcache.
*/
public function clear()
{
if (function_exists('opcache_reset')) {
return opcache_reset();
}
}
/**
* Get configuration values.
*/
public function getConfig()
{
if (function_exists('opcache_get_configuration')) {
return opcache_get_configuration();
}
}
/**
* Get status info.
*/
public function getStatus()
{
if (function_exists('opcache_get_status')) {
return opcache_get_status(false);
}
}
/**
* Pre-compile php scripts.
*/
public function compile($force = false)
{
if (!ini_get('opcache.dups_fix') && !$force) {
return ['message' => 'opcache.dups_fix must be enabled, or run with --force'];
}
if (function_exists('opcache_compile_file')) {
$compiled = 0;
// Get files in these paths
$files = collect(Finder::create()->in(config('opcache.directories'))
->name('*.php')
->notContains('#!/usr/bin/env php')
->exclude(config('opcache.exclude'))
->files());
// optimized files
$files->each(function ($file) use (&$compiled) {
try {
if (!opcache_is_script_cached($file)) {
opcache_compile_file($file);
}
$compiled++;
} catch (\Exception $e) {}
});
return [
'total_files_count' => $files->count(),
'compiled_count' => $compiled,
];
}
}
}