Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to install and use memcached in Windows for PHP?

Tags:

php

memcached

I have installed memcached binary file in Windows 7 and started it as server.

When I type wmic process get description, exetuablepath | findstr memcached.exe I get the response: memcached.exe c:\memcached\memcached.exe on command line.

When I try running the sample code on php.net, I get on my browser:

Fatal error: Class 'Memcache' not found in C:\DocumentRoot\Framework\index.php on line 3 Call Stack: 0.0010 335928 1. {main}() C:\DocumentRoot\Framework\index.php:0

So, what is it that I am doing wrong? I am using memcache.dll since memcached.dll does not exist for Windows I believe?

like image 503
Koray Tugay Avatar asked Feb 08 '13 17:02

Koray Tugay


People also ask

How do I enable Memcached PHP?

To enable the PHP Memcache extensions, you need to build PHP utilizing –enable-Memcache option when building, and configure it from the source. On Debian-based dispersions, you can use the php-Memcache package. To set global runtime configuration choices, specify the configuration option values within your php.

How do I know if PHP Memcached is installed?

You can look at phpinfo() or check if any of the functions of memcache is available. Ultimately, check whether the Memcache class exists or not. e.g. if(class_exists('Memcache')){ // Memcache is enabled. }

What does Memcached do in PHP?

Memcached puts often-used data in RAM, allowing it to be accessed a lot faster. Caching with Memcached works like this: A web browser requests a page, and the server runs PHP code to build it. PHP asks Memcached for the page's data via a Memcached extension.


1 Answers

A note to anyone who runs into issues with getting memcached working on Windows.

  • For starters ensure that you have the right version of the memcached dll and that it is accessible. There is a wide selection available at http://windows.php.net/downloads/pecl/releases/memcache/3.0.8/ and it is all too easy to choose the wrong version of memcached!.
  • If you are running PHP 5.5 you will additionally require php5.dll. You can get this here
  • You may need to edit your environment PATH settings so this dll can be found. Go to My Computer->Properties->advanced and click on Environment Variables to view/edit the path. You need to restart the computer if you edit this.
  • Ensure that the memcached server is installed. Ctrl + Alt + Del and check that memcached is present in your list of services
  • If not you need to *install it from the Cmd prompt run as administrator (from the start menu, choose accessories, click on command prompt and choose to run as administrator) c:\pathtomemcached\memcached.exe -d install
  • follow this with c:\pathtomemcached\memcached.exe -d start or net start “memcached Server”. On my installation the former does not work
  • Likewise I am unable to start memcached from the Services tab of the Task Manager
  • It is handy to be able to play around with memcached at a low level so enable telnet, if required, and from the command prompt type telnet. Now open port 11211 and try using memcached
  • It is also useful to be able to keep tabs on what is happening in memcached. phpMemCacheAdmin is by far the best tool for the job
like image 68
DroidOS Avatar answered Sep 28 '22 13:09

DroidOS