Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Can PHP get write access to Apache's log?

Status
Not open for further replies.

ptgophp

Programmer
Sep 22, 2005
3
US
Hi there,

I am a novice PHP programmer, and have a question on how the following task may be done with PHP/Apache.

When we fulfill a web request in PHP we need to log the response into a file for later processing. The response can be anywhere from 2k to 6k. We clocked our PHP app and it services about 60 requests per sec. I tried just creating a file for containing each response, but due to high request volume, we were generating 2,400 files in 400 seconds. This created too much load on the system, plus the resulting number of individual log files (one for each web
request) was unmanageable (not to mention using up all available iNodes or file handles).

We figured since Apache is ultra-efficient at logging (like how their access log files get sooo big yet this logging task does not noticeably drag down the server), can we in PHP somehow use Apache's logging service? It would be great if all PHP threads can just somehow pass Apache our log data and have it stash them in one big file (that rolls on some schedule). This way we avoid creating tons of little files, and our PHP threads can effectively share a log file handle without having to serialize (lock/unlock) access to the log file.

We've considered throwing these into a DB but can something like MySQL handle this kind of load?

Has anyone done this or have ideas or leads?

Thanks in advance for your help!
 
Thanks everyone for your thoughtful responses! We did not pursue writing to the apache log but we did look at using a db (sql lite) or sleepycat, the latter being the most lightweight embedded db we can find.

But then we started wondering, maybe instead of generating one cache file for each request we can generate one file every X minutes (that contain responses for the last X minutes). Less files = easier to manage = decrease overhead of creating new files = decrease expense of lock/unlock. And so far our prototype yields acceptable performance!

Thanks again for the help!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top