JP19
JP19

Reputation:

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, browser, 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

Upvotes: 0

Views: 859

Answers (2)

Darin Dimitrov
Darin Dimitrov

Reputation: 1039438

  1. Robust but could be a pain to implement
  2. Be careful for multithreading. What happens if two users call simultaneously your php script and the file is already open for writing.
  3. Same as 2 but the exception will occur in the C++ executable.

I would suggest you using a logging framework such as log4php.

Upvotes: 1

Your Common Sense
Your Common Sense

Reputation: 157989

You have this C++ executable. Called web-server. It logs every hit to your site already.

Upvotes: 4

Related Questions