我在启用memcache时遇到了一些麻烦。我正在运行Debian 9并安装了memcache。看起来一切正常
~$ ps aux | grep memcached
memcache 2341 0.0 0.0 335696 2648 ? Ssl 18:57 0:01 /usr/bin/memcached -m 64 -p 11211 -u memcache -l 127.0.0.1
olafHus 7486 0.0 0.0 12788 972 pts/1 S+ 21:41 0:00 grep memcached
我已检查模块是否已启用:
~$ sudo cat /etc/php5/conf.d/20-memcached.ini
; uncomment the next line to enable the module
extension=memcached.so
而且,我也得到了
~$ sudo netstat -tap | grep memcached
tcp 0 0 localhost:11211 0.0.0.0:* LISTEN 2341/memcached
最后我运行了/etc/init.d/apache2 restart
,sudo /etc/init.d/apache2 reload
和s udo /etc/init.d/memcached restart
。但是当我检查我的localhost时,一个简单的phpinfo()
所在的memcache没有列出。我已经按照this指令并输入以下文件来查看memcache是否正常工作
<?php
$mem = new Memcached();
$mem->addServer("127.0.0.1", 11211);
$result = $mem->get("blah");
if ($result) {
echo $result;
} else {
echo "No matching key found. I'll add that now!";
$mem->set("blah", "I am data! I am held in memcached!") or die("Couldn't save anything to memcached...");
}
?>
但它不起作用。有人知道发生了什么以及如何让memcache工作吗?
编辑:
这是日志的输出
$ sudo cat /var/log/apache2/error.log
[Mon Jul 10 18:23:10.671404 2017] [mpm_event:notice] [pid 29979:tid 140044669715648] AH00489: Apache/2.4.25 (Debian) configured -- resuming normal operations
[Mon Jul 10 18:23:10.671544 2017] [core:notice] [pid 29979:tid 140044669715648] AH00094: Command line: '/usr/sbin/apache2'
[Mon Jul 10 18:23:27.115014 2017] [mpm_event:notice] [pid 29979:tid 140044669715648] AH00491: caught SIGTERM, shutting down
[Mon Jul 10 18:23:27.170643 2017] [mpm_prefork:notice] [pid 4817] AH00163: Apache/2.4.25 (Debian) configured -- resuming normal operations
[Mon Jul 10 18:23:27.170737 2017] [core:notice] [pid 4817] AH00094: Command line: '/usr/sbin/apache2'
[Mon Jul 10 18:23:27.447314 2017] [mpm_prefork:notice] [pid 4817] AH00169: caught SIGTERM, shutting down
[Mon Jul 10 18:23:27.536634 2017] [mpm_prefork:notice] [pid 4873] AH00163: Apache/2.4.25 (Debian) configured -- resuming normal operations
[Mon Jul 10 18:23:27.536680 2017] [core:notice] [pid 4873] AH00094: Command line: '/usr/sbin/apache2'
[Mon Jul 10 18:26:41.201787 2017] [mpm_prefork:notice] [pid 4873] AH00169: caught SIGTERM, shutting down
[Mon Jul 10 18:26:41.292588 2017] [mpm_prefork:notice] [pid 6922] AH00163: Apache/2.4.25 (Debian) configured -- resuming normal operations
[Mon Jul 10 18:26:41.292635 2017] [core:notice] [pid 6922] AH00094: Command line: '/usr/sbin/apache2'
[Mon Jul 10 18:27:35.149322 2017] [mpm_prefork:notice] [pid 6922] AH00169: caught SIGTERM, shutting down
[Mon Jul 10 18:27:35.244846 2017] [mpm_prefork:notice] [pid 6981] AH00163: Apache/2.4.25 (Debian) configured -- resuming normal operations
[Mon Jul 10 18:27:35.244889 2017] [core:notice] [pid 6981] AH00094: Command line: '/usr/sbin/apache2'
[Mon Jul 10 18:29:32.870011 2017] [mpm_prefork:notice] [pid 6981] AH00169: caught SIGTERM, shutting down
[Mon Jul 10 18:29:32.960699 2017] [mpm_prefork:notice] [pid 26042] AH00163: Apache/2.4.25 (Debian) configured -- resuming normal operations
[Mon Jul 10 18:29:32.960738 2017] [core:notice] [pid 26042] AH00094: Command line: '/usr/sbin/apache2'
[Mon Jul 10 18:29:54.322087 2017] [mpm_prefork:notice] [pid 26042] AH00169: caught SIGTERM, shutting down
[Mon Jul 10 18:29:54.416333 2017] [mpm_prefork:notice] [pid 26089] AH00163: Apache/2.4.25 (Debian) configured -- resuming normal operations
[Mon Jul 10 18:29:54.416371 2017] [core:notice] [pid 26089] AH00094: Command line: '/usr/sbin/apache2'
[Mon Jul 10 18:32:55.998398 2017] [mpm_prefork:notice] [pid 26089] AH00169: caught SIGTERM, shutting down
[Mon Jul 10 18:32:56.092397 2017] [mpm_prefork:notice] [pid 30053] AH00163: Apache/2.4.25 (Debian) configured -- resuming normal operations
[Mon Jul 10 18:32:56.092431 2017] [core:notice] [pid 30053] AH00094: Command line: '/usr/sbin/apache2'
[Mon Jul 10 18:37:17.489919 2017] [mpm_prefork:notice] [pid 30053] AH00169: caught SIGTERM, shutting down
[Mon Jul 10 18:37:17.586762 2017] [mpm_prefork:notice] [pid 30260] AH00163: Apache/2.4.25 (Debian) configured -- resuming normal operations
[Mon Jul 10 18:37:17.586801 2017] [core:notice] [pid 30260] AH00094: Command line: '/usr/sbin/apache2'
[Mon Jul 10 18:37:21.451096 2017] [mpm_prefork:notice] [pid 30260] AH00169: caught SIGTERM, shutting down
[Mon Jul 10 18:37:24.067553 2017] [mpm_prefork:notice] [pid 30343] AH00163: Apache/2.4.25 (Debian) configured -- resuming normal operations
[Mon Jul 10 18:37:24.067594 2017] [core:notice] [pid 30343] AH00094: Command line: '/usr/sbin/apache2'
[Mon Jul 10 18:38:51.583610 2017] [mpm_prefork:notice] [pid 30343] AH00169: caught SIGTERM, shutting down
[Mon Jul 10 18:38:53.488078 2017] [mpm_prefork:notice] [pid 30595] AH00163: Apache/2.4.25 (Debian) configured -- resuming normal operations
[Mon Jul 10 18:38:53.488121 2017] [core:notice] [pid 30595] AH00094: Command line: '/usr/sbin/apache2'
[Mon Jul 10 18:39:59.404361 2017] [:error] [pid 30597] [client 127.0.0.1:38144] PHP Fatal error: Class 'Memcached' not found in /var/www/html/cache_test.php on line 2
[Mon Jul 10 18:39:59.404388 2017] [:error] [pid 30597] [client 127.0.0.1:38144] PHP Stack trace:
[Mon Jul 10 18:39:59.404394 2017] [:error] [pid 30597] [client 127.0.0.1:38144] PHP 1. {main}() /var/www/html/cache_test.php:0
[Mon Jul 10 18:40:05.482553 2017] [:error] [pid 30598] [client 127.0.0.1:38146] PHP Fatal error: Class 'Memcached' not found in /var/www/html/cache_test.php on line 2
[Mon Jul 10 18:40:05.482595 2017] [:error] [pid 30598] [client 127.0.0.1:38146] PHP Stack trace:
[Mon Jul 10 18:40:05.482607 2017] [:error] [pid 30598] [client 127.0.0.1:38146] PHP 1. {main}() /var/www/html/cache_test.php:0
[Mon Jul 10 18:46:58.898526 2017] [mpm_prefork:notice] [pid 30595] AH00169: caught SIGTERM, shutting down
[Mon Jul 10 18:46:59.004874 2017] [mpm_prefork:notice] [pid 31027] AH00163: Apache/2.4.25 (Debian) configured -- resuming normal operations
[Mon Jul 10 18:46:59.004915 2017] [core:notice] [pid 31027] AH00094: Command line: '/usr/sbin/apache2'
[Mon Jul 10 18:51:21.595950 2017] [mpm_prefork:notice] [pid 31027] AH00169: caught SIGTERM, shutting down
[Mon Jul 10 18:51:21.692445 2017] [mpm_prefork:notice] [pid 31243] AH00163: Apache/2.4.25 (Debian) configured -- resuming normal operations
[Mon Jul 10 18:51:21.692480 2017] [core:notice] [pid 31243] AH00094: Command line: '/usr/sbin/apache2'
[Mon Jul 10 18:54:33.454240 2017] [mpm_prefork:notice] [pid 31243] AH00169: caught SIGTERM, shutting down
[Mon Jul 10 18:54:33.539549 2017] [mpm_prefork:notice] [pid 2072] AH00163: Apache/2.4.25 (Debian) configured -- resuming normal operations
[Mon Jul 10 18:54:33.539598 2017] [core:notice] [pid 2072] AH00094: Command line: '/usr/sbin/apache2'
[Mon Jul 10 18:54:41.149185 2017] [mpm_prefork:notice] [pid 2072] AH00169: caught SIGTERM, shutting down
[Mon Jul 10 18:54:41.244007 2017] [mpm_prefork:notice] [pid 2115] AH00163: Apache/2.4.25 (Debian) configured -- resuming normal operations
[Mon Jul 10 18:54:41.244039 2017] [core:notice] [pid 2115] AH00094: Command line: '/usr/sbin/apache2'
[Mon Jul 10 18:54:45.901404 2017] [mpm_prefork:notice] [pid 2115] AH00171: Graceful restart requested, doing restart
[Mon Jul 10 18:54:45.922983 2017] [mpm_prefork:notice] [pid 2115] AH00163: Apache/2.4.25 (Debian) configured -- resuming normal operations
[Mon Jul 10 18:54:45.922999 2017] [core:notice] [pid 2115] AH00094: Command line: '/usr/sbin/apache2'
[Mon Jul 10 18:58:37.287228 2017] [mpm_prefork:notice] [pid 2115] AH00169: caught SIGTERM, shutting down
[Mon Jul 10 18:58:37.381938 2017] [mpm_prefork:notice] [pid 2524] AH00163: Apache/2.4.25 (Debian) configured -- resuming normal operations
[Mon Jul 10 18:58:37.381994 2017] [core:notice] [pid 2524] AH00094: Command line: '/usr/sbin/apache2'