Php

“Memcache 無法連接,連接被拒絕 (111)”?

  • August 31, 2015

首先…

我必須說,我對伺服器了解不多。我是那種不經常使用命令行的 php 開發人員。我在航站樓裡很不舒服。

不過,我正在學習。我不習慣在沒有託管主機的情況下將我的網站放在專用伺服器上。但是現在我是第一次擁有,需要自己安裝Memcache。

一些伺服器資訊

  • 產品:Media Temple 上的專用伺服器 (DV)
  • Parallels® Plesk Panel 12 或 cPanel® 11
  • CentOS 5.7(最終版)
  • 阿帕奇 2.2
  • PHP 5.4
  • YUM 包管理

我做了什麼

我已遵循本指南:https ://mediatemple.net/community/products/dv/204644340/installing-pecl-extensions

但當然用memcache而不是uploadprogress.

我已經檢查過,Memcache 已安裝並正在執行。並且$memcache = new Memcache;正在我的 php 程式碼中工作。但$memcache->connect('localhost', 11211);不工作。我收到錯誤消息:

Warning: Memcache::connect(): Can't connect to localhost:11211, Connection refused (111) in /var/www/vhosts/[mydomain]/httpdocs/index.php on line 10 Could not connect to memcache server

我曾嘗試更改localhost為伺服器的 IP 號,但沒有成功。

我用Google搜尋了很多,最後在關於安裝的文章和論壇執行緒中結束Memcached。所以我按照其中一個指南嘗試安裝它。但是收到錯誤消息No package memcached available.,因此無法安裝。

以下是我之後執行的命令範例:

Nothing to do
[root@mydomain /]# php -i | grep memcache
PHP Warning:  Module 'memcache' already loaded in Unknown on line 0
/etc/php.d/memcached.ini,
PHP Warning:  Unknown: It is not safe to rely on the system's timezone settings. You are *required* to use the date.timezone setting or the date_default_timezone_set() function. In case you used any of those methods and you are still getting this warning, you most likely misspelled the timezone identifier. We selected 'America/Los_Angeles' for 'PDT/-7.0/DST' instead in Unknown on line 0
memcache
memcache support => enabled
memcache.allow_failover => 1 => 1
memcache.chunk_size => 8192 => 8192
memcache.default_port => 11211 => 11211
memcache.default_timeout_ms => 1000 => 1000
memcache.hash_function => crc32 => crc32
memcache.hash_strategy => standard => standard
memcache.max_failover_attempts => 20 => 20
Registered save handlers => files user memcache 
OLDPWD => /memcached-1.4.9
_SERVER["OLDPWD"] => /memcached-1.4.9
[root@mydomain /]# ps aux | grep memcache
root      6434  0.0  0.0   9288   868 pts/0    S+   02:37   0:00 grep memcache
[root@mydomain /]# getenforce
Disabled

所以…

我忘了做什麼?

更新!

所以我最終成功了。如何:

  1. Google搜尋“查看是否安裝了 memcached 命令行 centos5”
  2. 點擊第三個結果,最終到了這個頁面:http ://cnedelcu.blogspot.se/2009/09/setting-up-and-using-memcached-memcache.html
  3. 按照步驟
  4. 成功安裝 Memcached 但未安裝 Memcache:
[root@mydomain /]# yum install php-pecl-memcache
Loaded plugins: fastestmirror, priorities
Loading mirror speeds from cached hostfile
* base: centos.mirror.nac.net
* extras: mirror.atlanticmetro.net
* updates: centos.mirror.nac.net
base                                                     | 1.1 kB     00:00     
extras                                                   | 2.1 kB     00:00     
updates                                                  | 1.9 kB     00:00     
Setting up Install Process
Resolving Dependencies
--> Running transaction check
---> Package php-pecl-memcache.x86_64 0:2.2.3-1.el5_2 set to be updated
--> Processing Dependency: php-api = 20041225 for package: php-pecl-memcache
--> Finished Dependency Resolution
php-pecl-memcache-2.2.3-1.el5_2.x86_64 from extras has depsolving problems
 --> Missing Dependency: php-api = 20041225 is needed by package php-pecl-memcache-2.2.3-1.el5_2.x86_64 (extras)
Error: Missing Dependency: php-api = 20041225 is needed by package php-pecl-memcache-2.2.3-1.el5_2.x86_64 (extras)
You could try using --skip-broken to work around the problem
You could try running: package-cleanup --problems
                       package-cleanup --dupes
                       rpm -Va --nofiles --nodigest
The program package-cleanup is found in the yum-utils package.

然而,似乎它不需要成功。Memcache 現在似乎可以工作了!

引用自:https://serverfault.com/questions/717962