Log visits in shared memory
I am trying to find the best way to visit logs using PHP. I currently have about 3000 requests per second and I write each visit to a CSV file. I was wondering if it is faster to log each visit in memory and then dump it to a CSV file after 100,000 entries? I have checked shmop
apc
and memcache
so far, but cannot find the right solution.
source to share
Your best bet is to use Lua with shared memory to store log entries and then create a timer that checks the size of the logged entries every X seconds and uses a co-socket to flush the cache to a sql file or database. Everyone should be non-blocking. And yes, you can pass Lua requests before passing it to PHP. You can also use nginx's default caching (buffer) and split the logs separately.
source to share