Log visits in shared memory

青春壹個敷衍的年華 提交于 2019-12-22 10:59:40

问题


I'm trying to find best way to log visits using PHP. Right now I have about 3000 request per second and I write each visit to CSV file. I was wondering is it faster to log each visit in memory somehow and then dump it to CSV file after 100 000 records? I've checked shmop apc and memcache so far but can't find proper solution.


回答1:


The best way is to use Lua with shared memory to store log entries, then create a timer which checks the size of logged entries every X seconds and uses a co-socket to dump the cache to a file or sql database. Should all be non-blocking. And yes you can pass requests to Lua before passing it to PHP. You could also use nginx default logfile caching(buffer) and parse the logs separately.



来源:https://stackoverflow.com/questions/30191227/log-visits-in-shared-memory

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!