Looking for more information on how to do PHP the right way? Check out PHP: The Right Way

Lorna Mitchell:
Logging to Stdout with Monolog
Jun 09, 2014 @ 14:08:10

Lorna Mitchell has a quick post today showing how you can use the popular Monolog logging library to log messages and data to stdout, the standard output stream of whatever is executing the script.

My worker scripts have really basic logging (as in, they echo when something happens, and I can see those in the supervisord logs). Which is kind of okay, but I wanted to at least add timestamps in to them, and maybe send emails when something REALLY bad happened. I'm a huge fan of Monolog so I grabbed that, but it wasn't immediately obvious which of the many and varied options I would need for this fairly simple addition. It turns out that the right thing to use is the ErrorLogHandler.

She includes a few lines of sample code that use the "ErrorLogger" to output the message. It includes the log level, a timestamp, the message itself and any additional contextual information you pass in.

tagged: monolog stdout output example library logging

Link: http://www.lornajane.net/posts/2014/logging-to-stdout-with-monolog

Joshua Thijssen:
PHP’s Resources and garbage collection
Jul 12, 2013 @ 15:54:34

Joshua Thijssen has put together a new post with details about garbage collection in PHP and a "nice bug/feature/whatsmathing" he found related to it and its performance.

I was playing around with writing a daemon and if you have any experience writing daemons (in any language), there are a few rules you have to live by. For instance, setting your effective uid and gid to a non-privileged user (in case you needed to do some privileged initialization, like opening a socket on a tcp port < 1024), setting the process as a group leader with posix_setsid(), and redirecting stdio file descriptions. And here something went wrong which took a while to find and fix..

He was creating a daemon and the script would just exit without a warning and not continue running. He narrowed down the issue to a few lines (with fopen and fclose) and went to debug it with strace to really see what was happening. He found some unexpected calls in the stack trace and, after some more digging, finally figured out it was a problem of both scope and cleanup that was resulting in the extra calls.

tagged: garbage collection resource stdin stdout stderr bug

Link: http://www.adayinthelifeof.nl/2013/07/10/phps-resources-and-garbage-collection


Trending Topics: