<?xml version="1.0"?>
<rss version="2.0">
  <channel>
    <title>PHPDeveloper.org</title>
    <link>http://www.phpdeveloper.org</link>
    <description>Up-to-the Minute PHP News, views and community</description>
    <language>en-us</language>
    <pubDate>Sun, 12 Feb 2012 15:40:22 -0600</pubDate>
    <ttl>30</ttl>
    <item>
      <title><![CDATA[Brian Moon's Blog: Check for a TTY or interactive terminal in PHP]]></title>
      <guid>http://www.phpdeveloper.org/news/16809</guid>
      <link>http://www.phpdeveloper.org/news/16809</link>
      <description><![CDATA[<p>
In a new post to his blog <i>Brian Moon</i> describes a need he had for detecting if the client or user calling a PHP script was <a href="http://brian.moonspot.net/tty-or-interactive-terminal-in-php">using an interactive terminal (TTY)</a> or not:
</p>
<blockquote>
Let's say I am trying to find out why some file import did not happen. Running the job that is supposed to do it may yield an error. Maybe it was a file permission issue or something. There are other people watching the alerts. What they don't know is that I am running the code and looking at these errors in real time.
</blockquote>
<p>
Since the errors were being sent to the log file, they were lost to the client/user on the other end left staring at their script wondering what went wrong. He ended up with a solution (a pretty simple one too) that uses <a href="http://www.php.net/posix_ttyname">posix_ttyname</a> and <a href="http://php.net/posix_isatty">posix_isatty</a>. He includes the little snippet of code he puts in his prepend file that checks for errors then checks for a TTY. If both are there, it turns off logging the errors to the file and sends them direct instead.
</p>]]></description>
      <pubDate>Fri, 02 Sep 2011 09:12:47 -0500</pubDate>
    </item>
    <item>
      <title><![CDATA[Sameer Borate's Blog: Tail functionality in PHP]]></title>
      <guid>http://www.phpdeveloper.org/news/16606</guid>
      <link>http://www.phpdeveloper.org/news/16606</link>
      <description><![CDATA[<p>
<i>Sameer Borate</i> has posted <a href="http://www.codediesel.com/php/tail-functionality-in-php/">an alternative to "tail"</a> that you can use to find the last X number of lines in a log file you'd like to follow without having the overhead of parsing the entire file.
</p>
<blockquote>
Frequently one needs to get the last few lines of some log files, whether php error logs or Apache logs. Most of these file sizes run into megabytes, which makes it difficult and time consuming to remotely open them using ftp. [...] The [example] is a simple but useful 'tail' implementation in PHP. I've encapsulated the tail function in a 'LogRead' class, which can be further enlarged by adding other useful log functions.
</blockquote>
<p>
His code opens a file pointer to the requested log, grabs the file size and uses the <a href="http://php.net/fseek">fseek</a> function to move the pointer to the line/location you've requested. Obviously, if the requested lines of data is large, it will still have some overhead, but this is a much better way for keeping track of the latest additions to a log. You can then use the "tail" method on the "LogRead" class to grab just the lines you want.
</p>]]></description>
      <pubDate>Tue, 19 Jul 2011 10:16:41 -0500</pubDate>
    </item>
    <item>
      <title><![CDATA[Josh Adell's Blog: Logging User Sessions Across Requests]]></title>
      <guid>http://www.phpdeveloper.org/news/16366</guid>
      <link>http://www.phpdeveloper.org/news/16366</link>
      <description><![CDATA[<p>
<i>Josh Adell</i> has a new post to the Everyman Software blog talking about a solution he and his team have developed for <a href="http://blog.everymansoftware.com/2011/05/logging-user-sessions-across-requests.html">logging user sessions across requests</a> with the help of the Zend_Log component and a custom logging formatter.
</p>
<blockquote>
One way to handle this is to put a request-specific identifier in every log message. But I shouldn't have to remember to append or prepend the identifier to their log messages. I'd rather have it happen automatically, without me or my teammates having to think about it. Here's a method we've been using to try and untangle the mess and retain the usefulness of our logs. The code uses Zend's logging component, but can easily be adapted to other log systems.
</blockquote>
<p>
Their example sets a custom log format message with placeholders for a timestamp, log ID number and the log message. A unique ID is then generated for the user's session and applied to the Zend_Log object. This data is then automatically applied to the log file's output without any extra hassle. The full sample code (pretty simple, really) is included.
</p>]]></description>
      <pubDate>Fri, 20 May 2011 09:10:06 -0500</pubDate>
    </item>
    <item>
      <title><![CDATA[Working Software Blog: Parsing the output of PHPs print_r function]]></title>
      <guid>http://www.phpdeveloper.org/news/15744</guid>
      <link>http://www.phpdeveloper.org/news/15744</link>
      <description><![CDATA[<p>
On the Working Software blog there's <a href="http://workingsoftware.com.au/page/Parsing_the_output_of_PHPs_printr_function">a recent post</a> looking at correcting a mistake that the developer made when choosing the logging method of his application - pushing the output of <a href="http://php.net/print_r">print_r</a> into a file.
</p>
<blockquote>
 recently deployed a job on which the timeline was so tight that my ability to type quickly was what made the difference between delivering on time or not. Everything was rushed, the budget was tight, it was one of those real seat of the pants deals and there was far too little testing done. [...] The only problem is that, in the 5 minutes before the site was supposed to go live, I didn't really have much time to thoughtfully prepare a logging system to record all this stuff and, in my haste, I settled for [a file_put_contents of the print_r of $_GET and $_POST].
</blockquote>
<p>
Obviously, this solution is useful for casual browsing of the information, but if you need any real data from it, it's a real chore. To help you with the task, they've put together a snippet of code that can work through your print_r output and return it in a much more handy line-by-line result. Full code is copy-and-paste ready in <a href="http://workingsoftware.com.au/page/Parsing_the_output_of_PHPs_printr_function">the post</a>.
</p>]]></description>
      <pubDate>Fri, 14 Jan 2011 12:19:00 -0600</pubDate>
    </item>
    <item>
      <title><![CDATA[NetTuts.com: Quick Tip: Email Error Logs with PHP]]></title>
      <guid>http://www.phpdeveloper.org/news/15674</guid>
      <link>http://www.phpdeveloper.org/news/15674</link>
      <description><![CDATA[<p>
In <a href="http://net.tutsplus.com/tutorials/php/quick-tip-email-error-logs-to-yourself-with-php">this quick tip</a> from NetTuts.com today they show you how to set up custom error logging for your PHP application with the help of the <a href="http://php.net/set_error_handler">set_error_handler</a> function.
</p>
<blockquote>
In today's video quick tip, we'll review the process of setting custom error handlers with PHP. Along the way, we'll also learn how to log and email those potential errors to ourselves. That way, even when your web application has been deployed, you'll be the first to know when an error is encountered.
</blockquote>
<p>
They make a custom handler, nettuts_error_handler, that takes in the error information and translates it into an error message that's emailed to an admin of the site. It also checks the error reporting level to see if it needs to display the error back to the user or not. This helpful hint is part of a screencast, but they've provided the code separately to make it easier to work with. 
<p>]]></description>
      <pubDate>Tue, 04 Jan 2011 08:58:45 -0600</pubDate>
    </item>
    <item>
      <title><![CDATA[Design-Ireland.net: Logging Messages to Scribe from PHP]]></title>
      <guid>http://www.phpdeveloper.org/news/15462</guid>
      <link>http://www.phpdeveloper.org/news/15462</link>
      <description><![CDATA[<p>
On the Design-Ireland.net site, there's a recent tutorial showing you how to <a href="http://www.design-ireland.net/article/Logging_Messages_to_Scribe_from_PHP">log messages to Scribe from PHP</a>. <a href="https://github.com/facebook/scribe">Scribe</a> is Facebook's open sourced server for aggregating log data streamed in from multiple places.
</p>
<blockquote>
n a previous tutorial, I showed you how to install Facebook Scribe on a Linux server. In this tutorial we will continue to look at Scribe, but this time from the client perspective. Note that this tutorial assumes that you already have your Scribe and Thrift environment set up as outlined in the <a href="http://www.design-ireland.net/article/Installing_Facebook_Scribe_on_Fedora_8">previous tutorial</a>. You can log messages to Scribe from many different languages. In this tutorial I will show you how to use Thrift to generate a PHP client, and then use that client from your own PHP project to log messages.
</blockquote>
<p>
The tutorial walks you through setting up Thrift to work with your PHP installation and gives an example script to send your first messages over to the Scribe server. They also show how you can go into the Scribe instance's folders and look for the log information you just inserted.
</p>]]></description>
      <pubDate>Fri, 19 Nov 2010 10:28:32 -0600</pubDate>
    </item>
    <item>
      <title><![CDATA[Brian Moon's Blog: Monitoring PHP Errors]]></title>
      <guid>http://www.phpdeveloper.org/news/15404</guid>
      <link>http://www.phpdeveloper.org/news/15404</link>
      <description><![CDATA[<p>
<i>Brian Moon</i> has <a href="http://brian.moonspot.net/monitoring-php-errors">a new post</a> to his blog that pulls together some of his thoughts on monitoring PHP applications and how to handle the error that might be thrown.
</p>
<blockquote>
PHP errors are just part of the language. Some internal functions throw warnings or notices and seem unavoidable. A good case is parse_url. The point of parse_url is to take apart a URL and tell me the parts. Until recently, the only way to validate a URL was a regex. You can now use filter_var with the FILTER_VALIDATE_URL filter. But, in the past, I would use parse_url to validate the URL. It worked as the function returns false if the value is not a URL. But, if you give parse_url something that is not a URL, it throws a PHP Warning error message. The result is I would use the evil @ to suppress errors from parse_url. Long story short, you get errors on PHP systems. And you don't need to ignore them.
</blockquote>
<p>
He talks about the two-step process he's upgraded to to help monitor and handle the errors that pop up - an <a href="http://us.php.net/manual/en/function.set-error-handler.php">error handler</a> that logs human-readable and json versions of the errors and something like <a href="http://circonus.com/">Circonus</a> to do metric tracking. He also mentions some external services recommended on twitter - <a href="http://hoptoadapp.com/">HopToad</a> and <a href="http://www.loggly.com/">Loggly</a>.
</p>]]></description>
      <pubDate>Tue, 09 Nov 2010 11:09:16 -0600</pubDate>
    </item>
    <item>
      <title><![CDATA[ServerGrove Blog: Logging MongoDB queries using Symfony 2 and Doctrine ODM]]></title>
      <guid>http://www.phpdeveloper.org/news/15230</guid>
      <link>http://www.phpdeveloper.org/news/15230</link>
      <description><![CDATA[<p>
On the ServerGrove blog today there's <a href="http://blog.servergrove.com/2010/10/05/logging-mongodb-queries-using-symfony-2-and-doctrine-odm/">a quick new post</a> showing a method you can use to log the queries to your MongoDB database in your Symfony2-based application.
</p>
<blockquote>
Symfony 2 comes with native support to connect to MongoDB using the DoctrineMongoDBBundle. Getting started is quite simple and there is not much that needs to be configured, but the manual does not say how to enable query logging although it is already possible with Symfony PR3. Query logging allows you to debug queries sent to the DB server by writing them in a log file. It is very useful for cases when you issue a query and you are not getting the results you expected. 
</blockquote>
<p>
The key is to add a "logger_class" value into your Symfony configuration file pointing to the "DoctrineMongoDBLogger" tool. The queries will then show up in your normal log files. They include a sample line along with a brief explanation of the values inside.
</p>]]></description>
      <pubDate>Tue, 05 Oct 2010 10:56:43 -0500</pubDate>
    </item>
    <item>
      <title><![CDATA[Paul Gregg's Blog: "tail -# file" in PHP]]></title>
      <guid>http://www.phpdeveloper.org/news/12402</guid>
      <link>http://www.phpdeveloper.org/news/12402</link>
      <description><![CDATA[<p>
<i>Paul Gregg</i> has <a href="http://pgregg.com/blog/2009/04/tail---file-in-php.html">written up an example</a> of what he calls "tail -# file for PHP" (starting from the end of file and moving backwards a given number of lines).
</p>
<blockquote>
Here I will demonstrate a fairly tuned method of seeking to the end of the file and stepping back to read sufficient lines to the end of the file. If insufficient lines are returned, it incrementally looks back further in the file until it either can look no further, or sufficient lines are returned.
</blockquote>
<p>
His script meets two goals - reading enough lines in for the request and keeping those lines to a minimum. His code grabs the size of the file and opens the file as a resource to fseek to a certain point and read in the lines from the defined start to finish and push them into an array. You can see the <a href="http://pgregg.com/projects/php/code/tail-10.phps">source here</a> and a <a href="http://pgregg.com/projects/php/code/tail-10.php">sample execution here</a>.
</p>]]></description>
      <pubDate>Fri, 24 Apr 2009 12:02:42 -0500</pubDate>
    </item>
    <item>
      <title><![CDATA[Evert Pot's Blog: Dangers of mutual dependencies]]></title>
      <guid>http://www.phpdeveloper.org/news/12084</guid>
      <link>http://www.phpdeveloper.org/news/12084</link>
      <description><![CDATA[<p>
In a <a href="http://www.rooftopsolutions.nl/article/228">recent post</a> to his blog <i>Evert Pot</i> warns against some of the issues that mutual dependencies in your applications.
</p>
<blockquote>
Much like most people, I try work out my class dependencies through a top-down 'waterfall'-ish approach. By attempting this, I think allows me to keep the structure very clear and understandable. [...] I try to apply the same model to instantiated objects and packages (groups of classes). When an object encapsulates another object, I attempt to make sure the sub-object object is not aware of the parent. When I design packages, I attempt to make sure 2 packages don't require 'each other'.
</blockquote>
<p>
He gives an example of where this could cause problems - a Database logger that has three types of logging included: file, syslog and database. Obviously the last of the three requires the Database class so they must always be used/included together.
</p>
<blockquote>
As a bonus a database-error could occur while logging, resulting in an endless loop (or segmentation fault if you're using PHP). [...] However, these types of situations are sometimes simply unavoidable (that's why we have include_once). When they are needed, they should be implemented with care and consideration.
</blockquote>]]></description>
      <pubDate>Fri, 06 Mar 2009 13:42:40 -0600</pubDate>
    </item>
  </channel>
</rss>

