I was looking for a way to store some data that's coming in through an API and be able to access that data from another instance of the same script. Basically when I get a request I want to hold the data for 5 seconds and see if another request comes in with one of the fields matching within 5 seconds. I've tried this a couple of ways with sessions and using APC. Below is the APC version of the code, the sessions version is the same with the APC bits switched out for corresponding session bits.
What happens is that the second instance of the script does not see the stored information no matter which mechanism I have tried for storing the data.
Thank you in advance for your help.
//data exists, this is the second request with matching data.
if(apc_exists('key')){
//do work
//delete first request data from storage so it does not get processed below.
apc_delete('key');
} else {
//no data for this key, store data and wait 5 secs.
apc_add('key', $data);
sleep(5);
//stored data still exists, this is the only request coming with this data.
if(apc_exists('key')){
//do work
} else {
//data no longer exists, taken care of by other instance, just exit.
exit();
}
APC is not guaranteed to work with CGI/FastCGI SAPI - you may better look into redis, memcached or other key-value storage engines, independent from php.