2023-06-05 11:23:16 +00:00
|
|
|
<?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' );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return $r;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static public function memcached() {
|
|
|
|
return class_exists( 'Memcache' ) || class_exists( 'Memcached' );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static public function memcached_memcached() {
|
|
|
|
return 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' );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
|
* @param boolean $binary_protocol
|
|
|
|
* @param string $username
|
|
|
|
* @param string $password
|
|
|
|
* @return boolean
|
|
|
|
*/
|
|
|
|
static public function is_memcache_available( $servers, $binary_protocol, $username, $password ) {
|
|
|
|
static $results = array();
|
|
|
|
|
|
|
|
$key = md5( implode( '', $servers ) );
|
|
|
|
|
|
|
|
if ( !isset( $results[$key] ) ) {
|
2024-03-28 09:40:06 +00:00
|
|
|
$memcached = Cache::instance(
|
|
|
|
'memcached',
|
|
|
|
array(
|
|
|
|
'servers' => $servers,
|
|
|
|
'persistent' => false,
|
2023-06-05 11:23:16 +00:00
|
|
|
'binary_protocol' => $binary_protocol,
|
2024-03-28 09:40:06 +00:00
|
|
|
'username' => $username,
|
|
|
|
'password' => $password
|
|
|
|
)
|
|
|
|
);
|
|
|
|
|
|
|
|
if ( is_null( $memcached ) ) {
|
2023-06-05 11:23:16 +00:00
|
|
|
return false;
|
2024-03-28 09:40:06 +00:00
|
|
|
}
|
2023-06-05 11:23:16 +00:00
|
|
|
|
|
|
|
$test_string = sprintf( 'test_' . md5( time() ) );
|
2024-03-28 09:40:06 +00:00
|
|
|
$test_value = array( 'content' => $test_string );
|
|
|
|
|
2023-06-05 11:23:16 +00:00
|
|
|
$memcached->set( $test_string, $test_value, 60 );
|
2024-03-28 09:40:06 +00:00
|
|
|
|
|
|
|
$test_value = $memcached->get( $test_string );
|
|
|
|
$results[ $key ] = ( ! empty( $test_value['content'] ) && $test_value['content'] === $test_string );
|
2023-06-05 11:23:16 +00:00
|
|
|
}
|
|
|
|
|
2024-03-28 09:40:06 +00:00
|
|
|
return $results[ $key ];
|
2023-06-05 11:23:16 +00:00
|
|
|
}
|
|
|
|
}
|