tags:

views:

42

answers:

1

I've been using http://code.google.com/p/phpbrowscap/ for a project, and it usually works nice. But a few times it's cache, which is plain php-files (see http://code.google.com/p/phpbrowscap/source/browse/trunk/browscap/Browscap.php#372 et. al.), has been "zeroed", i.e. the whole cache file has become large blob of NULLs.

Instead of trying to find out why the files become NULL, I though perhaps it might be better to change the caching strategy to something more resilient.

So I do wonder if you has any good ideas what would be a good solution; I've been looking at http://www.jongales.com/blog/2009/02/18/simple-file-based-php-cache-class/ and http://www.phpclasses.org/package/313-PHP-Cache-arbitrary-data-in-files-.html and I also though of just saving an serialized array to the file instead of pure php as it's been doing now; But I'm uncertain what approach I should target here.

I'm grateful for any insight into this area of technology, as I know it's complex from a performance point of view.

+1  A: 

What you're describing appears to be a bug in phpbrowscap. You may check what's causing it.

Anyway, phpbrowscap's strategy is a relatively sensible one because by writing the cache into a PHP file, it can also take advantage of opcode caches.

However, I think the best strategy would be to serialize the object and put it the result in a memory cache like APC. Another possible strategy would be to implement the functionality in an extension, which would always be in memory.

Artefacto
When I think about it I can see a possible race condition when two php processes intercedes updates (creation in my case). I wonder if a plain flock might suffice.
azatoth