I use PHP APC to store a lot of information (using apc_fetch() , etc.). This information sometimes needs to be analyzed and removed elsewhere.
The story goes, I get several hundred hits / sec. These hits increment various counts (using apc_inc() and friends). Every hour, I would like to iterate over all the values that I have accumulated, and do other processing with them, and then save them to disk.
I could do this as a random or temporary switch in each request, but this is a potentially long operation (it may take 20-30 seconds, if not several minutes), and I do not want to hang on this request for a long time.
I thought a simple PHP cronjob task would do this task. However, I can’t even get him to read the cache information.
<?php print_r(apc_cache_info()); ?>
Yeilds is apparently another APC memory segment, with:
[num_entries] => 1
(The only entry seems to be the operation code cache)
While my web server running from nginx / php5-fpm gives:
[num_entries] => 3175
Thus, they obviously do not share the same piece of memory. How can I either access the same piece of memory in a CLI script (preferred), or if it is simply not possible, then what is the safest way to execute a long sequence, say, a random HTTP request every hour?
For the latter, using register_shutdown_function() and immediately set_time_limit(0) and ignore_user_abort(true) perform a trick to guarantee completion and does not freeze any browser?
And yes, I know redis, memcache, etc., which would not have this problem, but now I stick with APC, since none of them can demonstrate the same speed as APC.