Util_Installed.php
2.82 KB
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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
<?php
namespace W3TC;
/**
* Checks if different server modules are enabled and installed
*/
class Util_Installed {
static public function opcache() {
return function_exists( 'opcache_reset' ) && ini_get( 'opcache.enable' );
}
static public function apc() {
return function_exists( 'apc_store' ) || function_exists( 'apcu_store' );
}
static public function apc_opcache() {
return function_exists( 'apc_compile_file' ) && ini_get( 'apc.enable' );
}
public static function is_opcache_validate_timestamps() {
return ini_get( 'opcache.validate_timestamps' );
}
public static function is_apc_validate_timestamps() {
return ini_get( 'apc.stat' );
}
static public function curl() {
return function_exists( 'curl_init' );
}
static public function eaccelerator() {
return function_exists( 'eaccelerator_put' );
}
static public function ftp() {
return function_exists( 'ftp_connect' );
}
static public function memcached_auth() {
static $r = null;
if ( is_null( $r ) ) {
if ( !class_exists( '\Memcached' ) )
$r = false;
else {
$o = new \Memcached();
$r = ( method_exists( $o, 'setSaslAuthData' ) &&
ini_get( 'memcached.use_sasl' ) );
}
}
return $r;
}
static public function memcached() {
return class_exists( 'Memcache' ) || class_exists( 'Memcached' );
}
static public function memcached_aws() {
return class_exists( '\Memcached' ) &&
defined( '\Memcached::OPT_CLIENT_MODE' ) &&
defined( '\Memcached::DYNAMIC_CLIENT_MODE' );
}
static function memcache_auth() {
static $r = null;
if ( is_null( $r ) ) {
if ( !class_exists( '\Memcached' ) )
$r = false;
else {
$o = new \Memcached();
$r = ( method_exists( $o, 'setSaslAuthData' ) &&
ini_get( 'memcached.use_sasl' ) );
}
}
return $r;
}
static public function redis() {
return class_exists( 'Redis' );
}
static public function tidy() {
return class_exists( 'tidy' );
}
static public function wincache() {
return function_exists( 'wincache_ucache_set' );
}
static public function xcache() {
return function_exists( 'xcache_set' );
}
/**
* Check if memcache is available
*
* @param array $servers
* @return boolean
*/
static public function is_memcache_available( $servers ) {
static $results = array();
$key = md5( implode( '', $servers ) );
if ( !isset( $results[$key] ) ) {
$memcached = Cache::instance( 'memcached', array(
'servers' => $servers,
'persistent' => false
) );
if ( is_null( $memcached ) )
return false;
$test_string = sprintf( 'test_' . md5( time() ) );
$test_value = array( 'content' => $test_string );
$memcached->set( $test_string, $test_value, 60 );
$test_value = $memcached->get( $test_string );
$results[$key] = ( $test_value['content'] == $test_string );
}
return $results[$key];
}
}