There is nothing mentioned in the PHP.net manual about thread safety.
We are running Hiphop PHP with nginx server. One server receives requests of the order of 30 millions in a day.
Team members are saying that they had previously observed issues with apc_store() when they used it to add some values across requests to the system. Due to multiple threads running, initiated by nginx it seems, some of the values were getting lost, because of multiple threads concurrently referring to the same value stored in the cache and trying to update them. Hence they switched to apc_inc() in those cases.
My Observations
- I did not find any differences in the values resulted from using these functions.
- The values seemed to tally with the number of logs in the nginx access log file for the same period of time.
This makes me believe both are thread safe. Please correct me if I am wrong.
Update
Here is some probably relevant part from /etc/hiphop/hiphop.hdf file -
Server {
SourceRoot = /var/cake_1.2.0.6311-beta/app/webroot
RequestTimeoutSeconds = 10
RequestMemoryMaxBytes = -1
DefaultDocument = fam/hiphop.php
Type = fastcgi
Port = 9000
IP = 0.0.0.0
ThreadCount = 140
ThreadRoundRobin = false
ThreadDropCacheTimeoutSeconds = 0
ThreadJobLIFO = false
StatCache = false
AlwaysUseRelativePath = false
RequestInitDocument = /var/cake_1.2.0.6311-beta/app/webroot/openx/www/delivery/startup.php
RequestInitFunction = requestStart
ForceServerNameToHeader = false
EnableKeepAlive = true
EnableEarlyFlush = true
ConnectionTimeoutSeconds = 120
# shutdown options
GracefulShutdownWait = 0 # in seconds
HarshShutdown = true
EvilShutdown = true
DanglingWait = 0
MaxPostSize = 8 # in MB
LibEventSyncSend = true
ResponseQueueCount = 0
DefaultCharsetName = UTF-8
APC {
EnableApc = true
TableType = concurrent
ExpireOnSets = true
}
}
But, doesn't look like it answers how Hiphop is configured in terms of APC variable usage - - configured to run as one single process with multiple threads or - configured to run with shared memory for APC.
with reference to https://github.com/petehunt/hiphop-php/blob/master/doc/runtime.memory_model.
Yes, it's thread safe! Apcu use
rwlockto promise it's thread safe, U can find this in source codeapcu/apc_cache.c.