1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* @file |
5
|
|
|
* Contains functions for OPcache module. |
6
|
|
|
*/ |
7
|
|
|
|
8
|
|
|
use OPCache\OPCache; |
9
|
|
|
use OPCache\OPCacheConfiguration; |
10
|
|
|
use OPCache\OPCacheStatus; |
11
|
|
|
|
12
|
|
|
/** |
13
|
|
|
* Implements hook_flush_caches(). |
14
|
|
|
*/ |
15
|
|
|
function opcache_flush_caches() { |
16
|
|
|
if (!drupal_is_cli()) { |
17
|
|
|
composer_manager_register_autoloader(); |
18
|
|
|
if (class_exists('\OPCache\OPCache')) { |
19
|
|
|
$opcache = new OPCache(); |
20
|
|
|
$opcache->cacheClear(); |
21
|
|
|
} |
22
|
|
|
} |
23
|
|
|
} |
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* Implements hook_menu(). |
27
|
|
|
*/ |
28
|
|
|
function opcache_menu() { |
29
|
|
|
$items = array( |
30
|
|
|
'opcache/%/%/reset/%' => array( |
31
|
|
|
'type' => MENU_CALLBACK, |
32
|
|
|
'access callback' => 'opcache_router_access', |
33
|
|
|
'access arguments' => array(1, 2), |
34
|
|
|
'page callback' => 'opcache_router', |
35
|
|
|
'page arguments' => array(3, 4), |
36
|
|
|
), |
37
|
|
|
'opcache/%/%/invalidate/%' => array( |
38
|
|
|
'type' => MENU_CALLBACK, |
39
|
|
|
'access callback' => 'opcache_router_access', |
40
|
|
|
'access arguments' => array(1 ,2), |
41
|
|
|
'page callback' => 'opcache_router', |
42
|
|
|
'page arguments' => array(3, 4), |
43
|
|
|
), |
44
|
|
|
'opcache/%/%/status' => array( |
45
|
|
|
'type' => MENU_CALLBACK, |
46
|
|
|
'access callback' => 'opcache_router_access', |
47
|
|
|
'access arguments' => array(1, 2), |
48
|
|
|
'page callback' => 'opcache_router', |
49
|
|
|
'page arguments' => array(3), |
50
|
|
|
), |
51
|
|
|
'admin/config/development/performance/opcache' => array( |
52
|
|
|
'type' => MENU_LOCAL_TASK, |
53
|
|
|
'title' => 'OPcache', |
54
|
|
|
'page callback' => 'drupal_get_form', |
55
|
|
|
'page arguments' => array('opcache_admin_form'), |
56
|
|
|
'access arguments' => array('administer site configuration'), |
57
|
|
|
'file' => 'opcache.admin.inc', |
58
|
|
|
'weight' => 10, |
59
|
|
|
), |
60
|
|
|
'admin/config/development/performance/opcache/backends' => array( |
61
|
|
|
'title' => 'Backends', |
62
|
|
|
'type' => MENU_DEFAULT_LOCAL_TASK, |
63
|
|
|
'weight' => -10, |
64
|
|
|
), |
65
|
|
|
'admin/config/development/performance/opcache/status' => array( |
66
|
|
|
'title' => 'Status', |
67
|
|
|
'type' => MENU_LOCAL_TASK, |
68
|
|
|
'page callback' => 'opcache_admin_status', |
69
|
|
|
'access arguments' => array('administer site configuration'), |
70
|
|
|
'file' => 'opcache.admin.inc', |
71
|
|
|
'weight' => 0, |
72
|
|
|
), |
73
|
|
|
'admin/config/development/performance/opcache/configuration' => array( |
74
|
|
|
'title' => 'Configuration', |
75
|
|
|
'type' => MENU_LOCAL_TASK, |
76
|
|
|
'page callback' => 'opcache_admin_config', |
77
|
|
|
'access arguments' => array('administer site configuration'), |
78
|
|
|
'file' => 'opcache.admin.inc', |
79
|
|
|
'weight' => 1, |
80
|
|
|
), |
81
|
|
|
'admin/config/development/performance/opcache/scripts' => array( |
82
|
|
|
'title' => 'Scripts', |
83
|
|
|
'type' => MENU_LOCAL_TASK, |
84
|
|
|
'page callback' => 'opcache_admin_scripts', |
85
|
|
|
'access arguments' => array('administer site configuration'), |
86
|
|
|
'file' => 'opcache.admin.inc', |
87
|
|
|
'weight' => 0, |
88
|
|
|
), |
89
|
|
|
); |
90
|
|
|
|
91
|
|
|
return $items; |
92
|
|
|
} |
93
|
|
|
|
94
|
|
|
/** |
95
|
|
|
* Access callback for OPcache router. |
96
|
|
|
*/ |
97
|
|
|
function opcache_router_access($request_time, $token) { |
98
|
|
|
composer_manager_register_autoloader(); |
99
|
|
|
$opcache = new OPCache(); |
100
|
|
|
if (!$opcache->isEnabled() || REQUEST_TIME - $request_time > 30) { |
|
|
|
|
101
|
|
|
return FALSE; |
102
|
|
|
} |
103
|
|
|
|
104
|
|
|
return $opcache->verifyToken($request_time, $token); |
105
|
|
|
} |
106
|
|
|
|
107
|
|
|
/** |
108
|
|
|
* Page callback for OPcache router. |
109
|
|
|
*/ |
110
|
|
|
function opcache_router($operation = 'reset', $arg = FALSE) { |
111
|
|
|
composer_manager_register_autoloader(); |
112
|
|
|
$opcache = new OPCache(); |
113
|
|
|
if ($operation == 'reset') { |
114
|
|
|
$opcache->reset($arg); |
115
|
|
|
} |
116
|
|
|
elseif ($operation == 'invalidate') { |
117
|
|
|
$opcache->invalidate($arg); |
118
|
|
|
} |
119
|
|
|
elseif ($operation == 'status') { |
120
|
|
|
print json_encode($opcache->status()); |
121
|
|
|
exit(); |
122
|
|
|
} |
123
|
|
|
|
124
|
|
|
return ''; |
125
|
|
|
} |
126
|
|
|
|
If an expression can have both
false
, andnull
as possible values. It is generally a good practice to always use strict comparison to clearly distinguish between those two values.