Setup: Apache; PHP 5.2.9; libevent (for memcached it's required) version 1.3; memcached server version 1.2.2 (tried 1.4.5, 1.4.0, now downgraded to 1.2.2, no difference); memcached php pecl module version 2.2.6.
Problem:
Similar to unresolved problems cannot store values into memcache and Super strange PHP error
None of those threads had resolved issue and none of the authors of questions followed recommendations given. I followed them all, and it still doesn't work.
Memcache
code doesn't show any error if I am connecting via PHP, but as soon as I'm trying to execute any command (such as getVersion
), I get the response:
Notice: memcache_get_version() [function.memcache-get-version]: Server 127.0.0.1 (tcp 11211) failed with: Failed reading line from stream (0) in /var/www/html/memcache.php on line 11
Solutions tried:
Connecting to memcache via command line is not working. After I type any command connection is closing.
[/usr/local/src]$ telnet 127.0.0.1 11211
Trying 127.0.0.1...
Connected to 127.0.0.1.
Escape character is '^]'.
stats
Connection closed by foreign host.
I tried $ memcached -S
to make sure memcached was compiled with SASL support disabled.
Response: "This server is not built with SASL support."
Also, one of the comments was
You may be running memcached without ASCII protocol support, such as if you ran:
$ memcached -B binary
If this is the case, remove the
-B
argument entirely, and PHP and telnet should work.
The memcache start line is:
memcached -d -m 1024 -u root -l 127.0.0.1 -p 11211
No B argument in it.
Any ideas?
To whom it might be interesting.
Issue resolved.
Here is where problem was(maybe it would help authors from 2 related treads).
On shared hosting sometimes you shouldn't use 127.0.0.1. Instead, use site's IP address.
So changing
to
and PHP code from
to
fixed the issue.
Thanks everyone!
I would talk to your sys sadmin. I think the there maybe a firewall involved.