Reputation: 1597
I have just had memcache installed on my server. I have started the server and i am now trying to connect to it via php
The server host installed the memcached extension and not the memcache extension.
So I found the examples of memcache and thought the two extensions would be similar which does not appear to be the case.
So what I am trying to get is a simple example of actually getting memcache working with the memcached extension.
for example, I want to connect to memcache, what is the code to connect to it?
memcache would be :
$memcache = new Memcache;
$memcache->connect('localhost', 11211);
but this does not work as there is no "connect", so how do i tell php to connect to memcache?
I have seen the "addServer" function , do I need to run that once in order for memcache to know it is there?
is it a case that once a server is added, memcached just knows its there and therefore there is no need for a "connect" call? or do i have to use the addServer function on every call?
Thanks for your help!
Upvotes: 0
Views: 319
Reputation: 52902
The docs for the memcached extension is useful. In particular, memcached will create the connection when needed, and will use the servers you've added by calling addServer or addServers.
From the manual page for Memcached::set:
$m = new Memcached();
$m->addServer('localhost', 11211);
$m->set('int', 99);
The connection will be handled internally by the memcached library when you call set.
Upvotes: 1