Reputation: 261
How to install memcached in windows XP 32 bit ?
I could install memcache successfully and can use using the below code
$m = new Memcache;
$m->connect('localhost',11211);
But I need to work with memcached like this,
$m = new Memcached();
$servers = array(
array('localhost', 11211)
);
$m->addServers($servers);
Now the above code is showing Memcached class not found. Since its not installed. So how can I install memcached in windows XP 32 bit
Upvotes: 1
Views: 960
Reputation: 3299
I had a similar problem and for those that don't want to (or can't, for whatever reason) run a virtual machine, I ended up having different code for running on windows vs running on linux.
When I ran the following:
$m = new Memcache;
print_r(get_class_methods($m));
I noticed that Memcache
doesn't have an AddServers()
method, that's something for Memcached
(see php.net docs on Memcache class compared to the php.net docs on Memcached class and notice there is a lot more to Memcached
!).
So for Windows (where you need to use Memcache
, no Memcached
available), the solution is to create your own short loop for adding multiple servers:
$m = new Memcache();
$servers = array(
array('localhost', 11211),
// ... other servers here
);
foreach ($servers as $s) $m->addServer($s[0], $s[1]);
If you need to have both sets of code for Windows and Linux available, you can always just enclose the above in if (PHP_OS == 'WINNT')
and put your Linux code in an else statement after it. So, something similar to:
$servers = array(
array('localhost', 11211),
// ... other servers here
);
if (PHP_OS == 'WINNT') {
$m = new Memcache();
foreach ($servers as $s) $m->addServer($s[0], $s[1]);
}
else {
$m = new Memcached();
$m->addServers($servers);
}
Upvotes: 2
Reputation: 3
having the same problem as you.
And after reading http://shikii.net/blog/installing-memcached-for-php-5-3-on-windows-7/ , i found out that the Memcached is designed for linux due to libmemcached.
Still waiting for the proper solution about this problem.
Is there anyone who can help us? thank you.
*sorry for my bad english.
Upvotes: 0