コード例 #1
0
ファイル: Server.php プロジェクト: marcbln/phpmemcacheadmin
 /**
  * Executing a Command on a MemCache Server
  * With the help of http://github.com/memcached/memcached/blob/master/doc/protocol.txt
  * Return the response, or false otherwise
  *
  * @param String $command Command
  * @param String $server Server Hostname
  * @param Integer $port Server Port
  *
  * @return String|Boolean
  */
 public function exec($command, $server, $port)
 {
     # Variables
     $buffer = '';
     $handle = null;
     # Socket Opening
     if (!($handle = @fsockopen($server, $port, $errno, $errstr, self::$_ini->get('connection_timeout')))) {
         # Adding error to log
         self::$_log = utf8_encode($errstr);
         Library_Data_Error::add(utf8_encode($errstr));
         return false;
     }
     # Sending Command ...
     fwrite($handle, $command . "\r\n");
     # Getting first line
     $buffer = fgets($handle);
     # Checking if result is valid
     if ($this->end($buffer, $command)) {
         # Closing socket
         fclose($handle);
         # Adding error to log
         self::$_log = $buffer;
         return false;
     }
     # Reading Results
     while (!feof($handle)) {
         # Getting line
         $line = fgets($handle);
         $buffer .= $line;
         # Checking for end of MemCache command
         if ($this->end($line, $command)) {
             break;
         }
     }
     # Closing socket
     fclose($handle);
     return $buffer;
 }
コード例 #2
0
ファイル: stats.php プロジェクト: marcbln/phpmemcacheadmin
                $stats[$server]['limit_maxbytes'] = $actual[$server]['limit_maxbytes'];
                $stats[$server]['curr_connections'] = $actual[$server]['curr_connections'];
                $stats[$server]['query_time'] = $actual[$server]['query_time'];
            }
        }
        # Saving new stats dump
        file_put_contents($file_path, serialize($actual));
        # Showing stats
        include 'View/LiveStats/Stats.phtml';
        break;
        # Default : No command
    # Default : No command
    default:
        # Initializing : making stats dump
        $stats = array();
        foreach ($_ini->cluster($cluster) as $name => $server) {
            $stats[$name] = Library_Command_Factory::instance('stats_api')->stats($server['hostname'], $server['port']);
        }
        # Saving first stats dump
        file_put_contents($file_path, serialize($stats));
        # Searching for connection error, adding some time to refresh rate to prevent error
        $refresh_rate = max($_ini->get('refresh_rate'), count($_ini->cluster($cluster)) * 0.25 + Library_Data_Error::count() * (0.5 + $_ini->get('connection_timeout')));
        # Showing header
        include 'View/Header.phtml';
        # Showing live stats frame
        include 'View/LiveStats/Frame.phtml';
        # include 'View/LiveStats/Graphic.phtml';
        # Showing footer
        include 'View/Footer.phtml';
        break;
}