Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Connecting and Testing Memcached with PHP

Tags:

php

memcached

after spending some time trying to setup Memcached on MAMP I can came into a bit of a pickle...

On my php info file it states memcached and displays the relevant information: Image of php info file

In order to learn and use Memcached I was using the following tutorial: http://net.tutsplus.com/tutorials/php/faster-php-mysql-websites-in-minutes/?search_index=1

This is where I encountered my first issue, this being connecting to the Cache Server: by using what they had stated, did not seem to work.

define('MEMCACHED_HOST', '127.0.0.1');
define('MEMCACHED_PORT', '11211');
$memcache = new Memcache;
$cacheAvailable = $memcache->connect(MEMCACHED_HOST, MEMCACHED_PORT);

I tried changing 127.0.0.1 to localhost, this did not work. My first point of call was to change memcache to memcached... This still did not work.

Therefore I just want to clear up how to connect and test a connection has been made with Memcached. If there is in fact a different connection between Memcache and Memcached? Or maybe I have set something up wrong? Any advice or guidance is appreciated :)

like image 287
HireLee Avatar asked Feb 18 '23 16:02

HireLee


1 Answers

First things first I suppose you should attempt to connect with telnet to memcahed.

telnet 127.0.0.1 11211

Here is some documentation on supported commands assuming you are able to connect: http://lzone.de/articles/memcached.htm

If you can't telnet to it then your setup is bad or you might have some firewall blocking it.

There are two clients for PHP, memcache and memcached. I would recommend using memcached (I have no idea why they named the client like it were a daemon - drives me nuts). The newer memcached client supports CAS operations and some other newer features.

The connection code you are using though looks more like memcache. With memcached you will want to set up a server pool or just use addServer().

like image 89
ficuscr Avatar answered Feb 26 '23 23:02

ficuscr