With a server running Apache and PHP via mod_fcgid, I'd like to log all requests handled by PHP into a separate file so that I can get a better idea of which requests are going through PHP versus being handled directly through the filesystem.

This is a site with some pretty complex rewrite rules in .htaccess (Wordpress with W3 Total Cache), which translates cached PHP requests into static file requests via mod_rewrite, so that cached requests don't even touch the PHP subsystem.

I want to make sure, therefore, that any log customization I do don't get thrown off by the mod_rewrite magic. Just because the request URI ends in .php, for example, doesn't mean that the request will ultimately end up being handled by PHP. I need to key based on whatever happens AFTER all the rewrite rules are applied.


Seems like the most straight-forward and fool proof way to do exactly that would be to including the logging code in every PHP page, probably at the end after calling flush() to send the output of the page, write to the log file, or if setting up locking and doing the file writing from there is too expensive, send something to zeromq (which has a php library I believe in the sample code) or a waiting server of some sort and let that server accept, disconnect, and then lock/write the log. That way if it's called from the PHP it will only log exactly what is run by PHP.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.