2016-04-12 28 views
1

我一个TCP端口上侦听的时候我能顺利拿到memcached的版本PHP 5.6获得PHP memcached的统计和版本的Unix套接字

<?php 
$m = new Memcached(); 
$m->addServer('localhost', 11211); 
print_r($m->getStats()); 
print_r($m->getVersion()); 
?> 

然后我得到的输出我希望

[email protected]:~# php memcached 
Array 
(
    [localhost:11211] => Array 
     (
      [pid] => 22165 
      [uptime] => 8 
      [threads] => 4 
      [time] => 1460472519 
      [pointer_size] => 64 
      [rusage_user_seconds] => 0 
      [rusage_user_microseconds] => 0 
      [rusage_system_seconds] => 0 
      [rusage_system_microseconds] => 0 
      [curr_items] => 0 
      [total_items] => 0 
      [limit_maxbytes] => 67108864 
      [curr_connections] => 5 
      [total_connections] => 6 
      [connection_structures] => 6 
      [bytes] => 0 
      [cmd_get] => 0 
      [cmd_set] => 0 
      [get_hits] => 0 
      [get_misses] => 0 
      [evictions] => 0 
      [bytes_read] => 8 
      [bytes_written] => 0 
      [version] => 1.4.25 
     ) 

) 
Array 
(
    [localhost:11211] => 1.4.25 
) 

当我更改为Unix套接字和指定端口0

$m->addServer('/var/run/memcached.sock', 0); 

我得到这个输出

Array 
(
    [/var/run/memached.sock:11211] => Array 
     (
      [pid] => -1 
      [uptime] => 0 
      [threads] => 0 
      [time] => 0 
      [pointer_size] => 0 
      [rusage_user_seconds] => 0 
      [rusage_user_microseconds] => 0 
      [rusage_system_seconds] => 0 
      [rusage_system_microseconds] => 0 
      [curr_items] => 0 
      [total_items] => 0 
      [limit_maxbytes] => 0 
      [curr_connections] => 0 
      [total_connections] => 0 
      [connection_structures] => 0 
      [bytes] => 0 
      [cmd_get] => 0 
      [cmd_set] => 0 
      [get_hits] => 0 
      [get_misses] => 0 
      [evictions] => 0 
      [bytes_read] => 0 
      [bytes_written] => 0 
      [version] => 
     ) 

) 
Array 
(
    [/var/run/memached.sock:11211] => 255.255.255 
) 

我运行的memcached这些参数只是用于测试的memcached

memcached support => enabled 
Version => 2.2.0 
libmemcached version => 1.0.18 
SASL support => yes 
Session support => yes 
igbinary support => no 
json support => no 
msgpack support => no 
memcached 
memcached support => enabled 
libmemcached version => 1.0.18 
memcached.compression_factor => 1.3 => 1.3 
memcached.compression_threshold => 2000 => 2000 
memcached.compression_type => fastlz => fastlz 
memcached.serializer => php => php 
memcached.sess_binary => 0 => 0 
memcached.sess_connect_timeout => 1000 => 1000 
memcached.sess_consistent_hash => 0 => 0 
memcached.sess_lock_expire => 0 => 0 
memcached.sess_lock_max_wait => 0 => 0 
memcached.sess_lock_wait => 150000 => 150000 
memcached.sess_locking => 1 => 1 
memcached.sess_number_of_replicas => 0 => 0 
memcached.sess_prefix => memc.sess.key. => memc.sess.key. 
memcached.sess_randomize_replica_read => 0 => 0 
memcached.sess_remove_failed => 0 => 0 
memcached.store_retry_count => 2 => 2 

回答

0

memcached -u root -s /var/run/memcached.sock -a 755 -vvvv 

我的PHP信息的问题结束了有关被许可,尽管我读到755是不够的。如果要保证memcached unix套接字在/ tmp文件夹中使用777工作,unix套接字将使其工作。

更安全的解决方案可以使用found here与php5-fpm或php7.0-fpm一起使用nginx或Apache。