Forum Moderators: coopster

Message Too Old, No Replies

Will writing to log file with PHP slow page load?

         

JohnKelly

1:00 am on Jan 13, 2005 (gmt 0)

10+ Year Member



To track page views for advertisers I'm logging each page access to a plain text file using a PHP script. Several sites log access using a different PHP script but to the same logfile.

Will doing this cause potential problems with page load times? Say simultaneous hits on pages, where it is attempting to write to the log file at the same time. If there a maxiumum number of file access per second?

jatar_k

3:03 am on Jan 13, 2005 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



why not apache logs? you can then not worry about concurrent users etc.

maybe this thread will give some extra ideas
Getting PHP session variables into your Apache logs [webmasterworld.com]

you could use that to add extra info right into your apache logs, it wouldn't have to be specifically session data, and help you track the hits better

JohnKelly

3:05 pm on Jan 13, 2005 (gmt 0)

10+ Year Member



Very interesting idea there, thanks. Since I also use Urchin stats I would have to make sure any changes to the logfile format wouldn't cause problems with Urchin. But definately worth looking into.

I'd still like to know what limitations there would be with my current method, if any.

jollymcfats

5:27 pm on Jan 13, 2005 (gmt 0)

10+ Year Member



The method jatar_k suggests can log to any file you like, it needn't interfere with your existing access logs.

Doing any disk writes in PHP will slow your page slightly. If there are simultaneous page views you also run the risk of interleaved writes to your log file- you'd see a jumble of data, with lines not beginning or ending in the right places. File locking can fix this, but it will slow down the page further.

I second the Apache log suggestion. The Apache logging facility is specifically designed for high-performance simultaneous writes, and it works well. I've long wished that PHP had native access to it like other mod_foo scripting modules do.