在共享内存中记录访问 [英] Log visits in shared memory

查看:61
本文介绍了在共享内存中记录访问的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试找到使用PHP记录访问的最佳方法.现在,我每秒大约有3000个请求,并且每次访问都写入CSV文件.我想知道将每次访问以某种方式记录到内存中,然后在100000条记录后将其转储到CSV文件中,会更快吗?到目前为止,我已经检查了shmop apcmemcache,但是找不到合适的解决方案.

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.

推荐答案

最好的方法是将Lua与共享内存一起使用来存储日志条目,然后创建一个计时器,该计时器每X秒检查一次记录条目的大小并使用一个co -socket将缓存转储到文件或sql数据库.应该都是非阻塞的.是的,您可以在将请求传递给PHP之前将请求传递给Lua. 您还可以使用nginx默认日志文件缓存(缓冲区)并分别解析日志.

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.

这篇关于在共享内存中记录访问的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆