DevShed has posted a new tutorial today looking at one of the more useful tools a developer can add into an application - logging.
If there is no logging mechanism, then if there's a goof-up in a production environment, you have absolutely no idea what went wrong. The only thing which a support developer can do in this case is to reproduce the issue at the developer end, which sometimes work and sometimes don't.
The look at the types of logging (trace logs, audit logs and user logging/history) and create a simple class that allows flexibility for file location, priority and timstamping. Their script contains a writelog method that does all the work (including pushing it through the PEAR logging class).
On the ThinkPHP blog today, Annika Rabeashares a method for outputting dates in words rather than in the usual numbers most applications use.
Recently, I have to output the age of a date in words and didn't have a framework to work with. The first steps were to parse the given date into an array and create a timestamp with the individual parts. The difference between the timestamp of now and the created timestamp yielded the age in seconds. The result can be used to compare with seconds of a day, week, etc.
The code snippet in the post outputs the difference between two timestamps (then and now) it a bit more friendly way (ex. 4 months, 2 weeks, 2 days).
Hasin Hayder has posted his own response to a recent "relative time" article (showing users things like "received 2 days and 3 hours ago") with a more precise method for doing something similar:
This function is production ready and you can use it in any of your application which mainly works with these date difference. I have found it somewhere in web, just forgot the source. Thanks to the unknown author of this excellent function.
The rest of the post is the function itself that takes in the interval string (formatting), the start date, end date and whether to use timestamps or not.
On the Photogapple.co.uk blog today, there's some handy code that can definitely be useful when working with dates in PHP - a function to find the difference between the current time and a timestamp you give it.
I found it incredibly difficult to find any form of time_since function in php so to save anyone else the trouble to hunting through hundreds of useless websites here is the function you may want to use, written by Natalie Downe (you don't want to know how long it took to hunt it down).
The function takes in the value, subtracts the two timestamps and loops through an array of "time chunks" to each other to show nicely formatted output of how long the difference it.
If you've ever had the frustration of working with Ajax in Internet Explorer and have noticed it caching the requests/results, you might want to check out this new post on the JSLabs blog for a helpful hint.
While working on an AJAX project over the weekend, I ran into the following issue: (through a GET request), every time I tried to call a certain function, It was returning the same data (which was supposed to be different each time)
First, he tried just changing the headers (via PHP's header function) to see if IE would understand the new message, but to no avail. He finally figured out that, despite whatever headers were sent or how much the content changed, what he really needed to do was to provide the script some kind of unique identifier with each request (just appended to the url) so that IE knew the request was different. His weapon of choice was a date/time value.
DevShed is wrapping up their "Building Proxy Classes with PHP5" series today with this last tutorial about working with directory iterators and proxy classes.
Since in the first part of the series I showed you how to create a proxy class for processing simple XML strings, in this installment I'm going to teach you how to create a proxy object that can be used in conjunction with the "DirectoryIterator" class that comes with PHP 5.
They start with the definition of a proxy class, the base to start from, and improve its functionality through additional methods like getSize, getPath, and getTimeStamps (using the iterators). The complete the development by pulling the parts together and creating a final example that loops through a given path and displays various info about the directory/files inside (size, names, timestamp, etc).
DevShed continues its look at the DirectoryIterator functionality in PHP5 with the second part of the series today - "Finding Paths, Timestamps and More with the DirectoryIterator Class in PHP".
Are you interested in having at your disposal a quick reference for working with the "DirectoryIterator" class that comes with PHP 5? Then this might be the article that you've been waiting for! Welcome to the second tutorial of the series "A Close Look at the DirectoryIterator Class in PHP 5." Over the course of this set of installments, you'll find complete coverage of the most important methods bundled with this class, and learn how to take advantage of their excellent functionality.
New from PHPit.net today, there's this tutorial on the creation of a "who's online" script with PHP.
In this tutorial I will show you how to create your own "Who's Online" script, which is often found on message boards and other community scripts. We will first create a really simple script, and after that add a few more features like the location of each visitor. But first, let me explain how our "Who's Online" script is going to work.
The script stores an IP and a timestamp in the database, and will keep note of their last page request. After a bit, when they are no longer making requests, it will remove them from the list. The little trick behind it is a "web bug" - a small script that actually runs as a small PHP-created image...