How to install PHP 7 extension "memcache" on Windows

Mihailo picture Mihailo · Aug 23, 2016 · Viewed 20k times · Source

I'm having huge problems installing memcached extension for php.

Currently using:

OS: Windows 10 x64
PHP: 7.0.1 via XAMPP
Apache: 2.4.18 (Win32)

I have successfully installed memcached in C:/memcached the service is running.

But the problem starts when trying to add the memcache php extension. I've tried numerous versions of php_memcache.dll and non seem to be working.
I did include the extension in php.ini extension=php_memcache.dll

When i run php -m memcache is not listed and at the top i recieve the error:

PHP Startup: Unable to load dynamic library 'C:\xampp\php\ext\php_memcache.dll'
- The specified module could not be found.

And when I try running a test.php for memcache initialization i recive the Class not found exception

This is a huge problem, because I need it for running selenium tests.

Answer

Sherif picture Sherif · Aug 23, 2016

The memcached service doesn't actually install the PHP memcached extension for you. It only installs the memcached server used to store your cache.

You'll need to download the Windows DLL from the PECL repository first (click on the blue Windows DLL link). Then you must add the extension=php_memcache.dll line to the correct php.ini file for your SAPI. Also, note the extension DLL file needs to be placed in the correct path for your XAMPP installation.

For Apache, simply create a script in your document root with the line <?php phpinfo(); and try loading that in your web browser. You should see a line at the top labeled Loaded configuration (php.ini) which gives you the full path to your loaded php.ini file. On Windows the path may actually appear different than what is stated in phpinfo() if you installed PHP through something like XAMPP. So you may need to rely on XAMPP to locate the correct php.ini file.

For the CLI SAPI, you can use php.exe --ini to do the same. Again, you may need to rely on the XAMPP package if it has modified your configuration path (since this is a compile time directive).

After making your changes to php.ini you will need to restart PHP for the changes to take effect.


Since you're using PHP 7 on Windows it's probably also important to note that the compiled DLL from PECL may not actually work under apache for Windows, because you're more than likely using a theaded SAPI. So make sure you are downloading the correct version. As far as I can tell that version is only compiled to work with up to PHP 5.6. The github alternative, for PHP 7, available at https://github.com/nono303/PHP7-memcahe-dll as mentioned in the comments is tested under non-thread safe. So you may only be able to get this working for your CLI scripts on Windows.