Search code examples
phpapc

PHP - usage of apc_store


I have to store a timestamp on my PHP server to be used with different clients and I found apc_store.

First, how long does it keep the data?

Secound, how can I check if the variable is set? is isset() will work here?

Third, the data can be used from differnt clients using diffrent machins at the same time? (request after request..).

Thanks!


Solution

  • Directly from the PHP manual, third parameter, ttl

    ttl Time To Live; store var in the cache for ttl seconds. After the ttl has passed, the stored variable will be expunged from the cache (on the next request). If no ttl is supplied (or if the ttl is 0), the value will persist until it is removed from the cache manually, or otherwise fails to exist in the cache (clear, restart, etc.).

    You can check if a value is "stored" by calling apc_exists.

    Yes, beware that the cache is per process, for example, running X number of php-fcgi processes will have its own cache and thus its own values. If you want a centralized place, you might want to look at memcached instead. (or something like it)