Memcache Funktionen

Inhaltsverzeichnis

User Contributed Notes 13 notes

When installing the memcache module for Apache/PHP with a non-standard location it seems like there is no way to define the location when configuring for build. You'll get an error complaining about being unable to find php_session.h. I modified configure to try the PREFIX location too and that seems to have worked fine.

one more "intelligent" cache aggregator:https://svn.shadanakar.org/onPHP/ trunk/core/Cache/AggregateCache.class.phpcan be used with several cache connectors - memcached, filesystem, etc.(remove whitespace manually)

Here is a simple memcached aggregator class which distributes the cache among multiple cache servers. If a server fails, the load is redistributed automatically. It uses persistent connections.

The constructor takes an array of arrays, with each inner array representing a server, with a 'server' (string) attribute that is the IP addres or host name of the memcached server, and a 'port' (int) attribute that is the port number on which memcached is running on the server.

All of the existing memcached API functions are implemented except getStats() and getVersion(), which are server-specific.

If you are trying install this module for PHP 5.2 under Windows but it won't load on startup, make sure you have all your dependencies including the correct thread-safety build of PHP.

For hours I tried to track down why I couldn't load php_memcache.dll, and finally used Dependency Walker (from http://www.dependencywalker.com) on the .dll file. This made me realize that while I was using the version of PHP 5.2.5 that was non-thread safe, the .dll offered by pecl4win was expecting the thread safe version of PHP. Once I rectified this, everything worked fine.

For run memcached in a windows box: (tested with latest php,apache and memcache in xp sp2)

a) download the php_memcache.dll it can be found in the pecl file.

b) put the dll in the extension folder (c:/php/extension for example). You cannot miss this folder because they are filled with php*.dll files. In some cases the extension folder used is the system32, a non-standard way to put dll but still works.

c)configure the php.ini
; i put this like the latest extension
extension=php_memcache.dll

e)Remember to install the service and to start the service memcached.exe -d install for install and run services.msc for start the memcached service (or restart the system).

f) check the firewall ports.

Finally restart the apache/iis and runs some test. At least in phpinfo must show some info about the memcache.

Final notes :The "awe" about memcache is not only can help for speed some process (or reduce the cpu use), also can be used like a global session for store a whole object also this "global session" is shared among all the users, like APPLICATION used in ASP. So (for example) it's possible to do a user counter without needing of database or writing a file.

In the memcache PECL extension version 2.2.5, the delete function does not work with memcached 1.4.3. To work around this, here is a version of the memcache PECL extension with a patch provided by harv at pringo dot com applied:

The above class will cause an error if all cache servers are down. The preferred behavior is to just have a cache miss (or take no action in the case of write operations) and return false, so the app can run in non-cached mode if all cache servers are down.

To make this happen, simply change the connection usage to look something like this in each affected function. This code is for the get() function: