Php efficiency question --> Database call vs. File Write vs. Calling C++ executable
What I wish to achieve is - log all information about each and every visit to every page ofmy website (like ip address, brows开发者_如何转开发er, referring page, etc). Now this is easy to do.
What I am interested is doing this in a way so as to cause minimum overhead (runtime) in the php scripts. What is the best approach for this efficiency-wise:
1) Log all information to a database table
2) Write to a file (from php directly)
3) Call a C++ executable, that will write this info to a file in parallel [so the script can continue execution without waiting for the file write to occur ...... is this even possible]
I may be trying to optimize unnecessarily/prematurely, but still - any thoughts / ideas on this would be appreciated. (I think efficiency of file write/logging can really be a concern if I have say 100 visits per minute...)
Thanks & Regards,
JP
You have this C++ executable. Called web-server. It logs every hit to your site already.
- Robust but could be a pain to implement
- Be careful for multithreading. What happens if two users call simultaneously your php script and the file is already open for writing.
- Same as 2 but the exception will occur in the C++ executable.
I would suggest you using a logging framework such as log4php.
精彩评论