Viewing: class.MemcachedInstance.php
<?php class MemcachedInstance extends A2OptBase { public $id; public $user; public $perms; public $size; public $threads; public $max_connections; public $sequential_requests; public $socket_path; public $socket; public $pidfile; public $instance; public function __construct($id, $user) { if (file_exists('/usr/bin/selectorctl')) { $installed_extensions = shell_exec("/usr/bin/selectorctl --interpreter=php --user={$user} --list-user-extensions"); } else { $installed_extensions = shell_exec('php -m'); } $extension_array = explode("\n", $installed_extensions); $conf = ''; $this->id = $id; if (!$this->username) { $this->user = $user; $this->username = $user; } else { $this->user = $this->username; } $this->perms = 770; $this->size = 16; $this->threads = 1; $this->max_connections = 1024; $this->sequential_requests = 20; $this->socket_path = "/opt/memcached/run/{$user}/memcached-{$this->id}.sock"; $this->socket = "unix:///opt/memcached/run/{$user}/memcached-{$this->id}.sock"; $this->pidfile = "/opt/memcached/run/{$user}/memcached-{$this->id}.pid"; if (file_exists("/opt/memcached/etc/conf/{$user}.conf")) { $conf = file("/opt/memcached/etc/conf/{$user}.conf"); $found = false; $instance = ''; for ($line = 0;$line < count($conf) && !$found;$line++) { $instance = explode(',', trim($conf[$line])); if ($instance[0] == $id) { $found = true; } } if (is_array($instance)) { $this->id = $instance[0]; $this->user = $instance[1]; $this->perms = $instance[2]; $this->size = $instance[3]; $this->threads = $instance[4]; $this->max_connections = $instance[5]; $this->sequential_requests = $instance[6]; $this->socket_path = "/opt/memcached/run/{$user}/memcached-{$this->id}.sock"; $this->socket = "unix:///opt/memcached/run/{$user}/memcached-{$this->id}.sock"; $this->pidfile = "/opt/memcached/run/{$user}/memcached-{$this->id}.pid"; } } if (in_array('memcached', $extension_array)) { $this->socket = $this->socket_path; } $redis_enabled = false; $redis_socket = ''; if (file_exists("/home/{$this->username}/.redis/redis.sock")) { $redis_enabled = true; $redis_socket = "/home/{$this->username}/.redis/redis.sock"; } if (!$this->is_cagefs()) { $running_processes = shell_exec('ps -ax'); $process_array = explode("\n", $running_processes); foreach ($process_array as $process) { if (strpos('redis-server 127', $process) === false) { // not found } else { $redis_enabled = true; $redis_socket = '127.0.0.1:6379'; } if (strpos('memcached -p 11211', $process) === false) { // not found } else { $this->socket = '127.0.0.1:11211'; $this->socket_path = '127.0.0.1:11211'; } } } $this->instance = (object) [ 'id' => $this->id, 'user' => $this->user, 'perms' => $this->perms, 'size' => $this->size, 'threads' => $this->threads, 'max_connections' => $this->max_connections, 'sequential_requests' => $this->sequential_requests, 'socket_path' => $this->socket_path, 'socket' => $this->socket, 'pidfile' => $this->pidfile, 'redis_enabled' => $redis_enabled, 'redis_socket' => $redis_socket, ]; } public function get_instance() { return $this->instance; } public function check() { if ( isset($this->id) && isset($this->user) && isset($this->perms) && isset($this->size) && isset($this->max_connections) && isset($this->sequential_requests) && isset($this->socket_path) && isset($this->pidfile) && isset($this->socket) && is_numeric($this->perms) && is_numeric($this->size) && is_numeric($this->max_connections) && is_numeric($this->sequential_requests) ) { return true; } else { $this->error('The Memcached instance given was missing information.'); } return false; } }
Return