News Feed
Sections

News Archive
feed this:

Brian Moon's Blog:
in_array is quite slow
June 06, 2008 @ 09:36:47

Brian Moon had a problem - one of his cron jobs was lasting for much longer (hours!) than it should have been. He tweaked, tested and debugged the script and finally came down to a call to in_array, something he comments on as being "quite slow".

See, this job is importing data from a huge XML file into MySQL. After it is done, we want to compare the data we just added/updated to the data in the table so we can deactivate any data we did not update. [...] We then compared the two arrays by looping one array and using in_array() to check if the value was in the second array. [...] So, that was running for hours with about 400k items. Our data did not contain the value as the key, but it could as the value was unique.

He method, replacing the in_array call that had to do a full array scan for each time through the loop with an isset/unset combo on the unique key, changed the execution time down from about 4 hours to 0.8 seconds.

1 comment voice your opinion now!
inarray compare array unset isset unique key execution time



Hasin Hayder's Blog:
WorldTimeEngine - How about making your own in PHP?
March 10, 2008 @ 11:17:00

Hasin Hayder has posted an example of a "world time search" he's worked up that uses the geonames.org and Yahoo! developer APIs to pin down the time at any given location.

I recently came by this site WorldTimeEngine where users can search the local time of any place using the name, street address or just latitude and longitude. Since that time I was thinking how easily you can make your own. As long there are some good people over there (For Geocoding API) - its a not a big deal, you know?

His script pulls the location of the place (latitude/longitude) from the Yahoo! geocoding API and passes that back into the geonames web service to get the local time. The result is an array with the lat/long, address you submitted and the time output in a standard string.

0 comments voice your opinion now!
world time engine example yahoo api webservice geonames


Developer Tutorials Blog:
Give Your Visitors a Relative Time
March 07, 2008 @ 11:19:00

Following on the heels of this post to the SitePoint blog (about "roughtime"), Akash Mehta has posted his own version of providing users with something a little different - relative time.

I understood the merits of the approach, but it struck me that a relative time might be a little more useful for many situations. For example, in a fast moving discussion, a short timestamp (e.g. 8:30 AM) as well as a verbal summary of how long ago the time was (e.g. "4 hours ago", "20 minutes ago") are most useful to the user. [...] Now, I figured this could be achieved very easily in PHP - and it could.

His code is included showing a series of if/else comparisons that change the values to their hour/minute/second counterparts. He also recommends the PEAR Numbers_Words package to help with readability.

0 comments voice your opinion now!
relative time pear numberswords since


SitePoint WebTech Blog:
Give Your Visitors a Rough Time
March 06, 2008 @ 08:44:00

In a new post to the Web Tech blog over on SitePoint, Toby Somerville has posted something he calls "RoughTime" - his method for displaying a more "human friendly" output of a timestamp.

When asked the time, we generally don't need to be military accurate with our response [...] we generally communicate the approximate time. i.e. 'its nearly ten' or 'its just gone half past three'. Yet on the web, time is generally shown as '12:24:13 AM', or similar â'" not very visitor friendly.

His RoughTime uses two switch statements to map the hour and minute values to different strings. For example, minutes between 15 and 20 become "quarter past" and the hours are changed over from numeric versions to their word counterparts.

0 comments voice your opinion now!
roughtime switch approximate time hour minute translate


Leon Chevalier's Blog:
Improve website load time by 500% with 3 lines of code
January 23, 2008 @ 12:09:00

Leon Chevalier has posted about a class he's developed (you can download it here) that can help to speed up the load times for your site.

There are 4 relatively easy ways by which you can speed up the time it takes a browser to download a page. Following on from my post on joining CSS and JavaScript files, I have written a PHP script which will automatically do all of the above.

He gives example code of the class in action and includes some screenshots of the benchmarks from the YSlow Firefox extension showing the improvements.

0 comments voice your opinion now!
website load time compress gzip class download


PHPWomen.org:
elePHPants
January 18, 2008 @ 07:56:00

To help "sweeten the deal" a bit and encourage you to give towards the causes that the PHP Women are trying to accomplish, they're offering a special little bonus for those who donate at a certain level:

Cal Evans from the Zend DevZone - being the awesome guy that he is - has graciously offered to mail out to the first 10 people who donate to PHPWomen $50 or more, a PHP elePHPant. Yep - you get one of the hard to find and much sought after plushy PHP elePHPants.

You can find out more about the goals for their fund raising in this other post to the PHPWomen.org blog as well as information on submitting whatever you feel like donating (time or money).

0 comments voice your opinion now!
elephpants stuffed toy donate money time phpwomen


Nessa's Blog:
Common PHP Errors
December 10, 2007 @ 12:05:00

Nessa has set up a post in an effort to help budding PHP developers out there with some of the most common problems they might come across in their work and how to handle them a bit more gracefully with error handling:

I'm going back to the basics here, you know, when you wrote your first PHP script and saw an ugly-ass error message pop up on your screen? Error messages are the best tool a programmer has.

She talks about how to set up the error reporting first, making sure that you're getting things up and useful. From there she describes some of the common errors that you might see including:

  • Parse errors
  • MySQL Result source errors
  • Stream errors
  • Max Execution Time errors

Check out the rest of the post for more types.

0 comments voice your opinion now!
error handling parse mysql resource stream execution time error handling parse mysql resource stream execution time


David Goodwin's Blog:
PHP DateTime vs mktime / strtotime in Propel
September 20, 2007 @ 12:52:00

David Goodwin, a developer on the Propel project has posted about a new feature included in the latest PHP version, the DateTime functionality, and how they put it to use in Propel.

One of the relatively new features in PHP 5.2, is the DateTime class/functions. It has a few useful functions (date_parse, date_date_set, date_time_set etc) which make dealing with dates and times easier (date_parse provides some useful error info too).

He also mentions the ability of the functionality to handles dates before 1970 or after 2038, a common problem with PHP's native date functionality. He illustrates how it's useful by describing the change they made in Propel store DateTime objects instead of the integer timestamps like before.

0 comments voice your opinion now!
datetime date time functionality propel mktime datetime date time functionality propel mktime


Ryan Grove's Blog:
Minify combines, minifies &caches JavaScript & CSS files to speed up page loads
May 04, 2007 @ 16:52:00

This new entry on Ryan Grove's blog today points out a handy little tool written in PHP that can be used to (somewhat) reduce the time it takes for your pages to download.

Minify is a PHP library that attempts to fix this problem by combining multiple CSS or JavaScript files into one download. By default, it also removes comments and unnecessary whitespace to decrease the amount of data that must be sent to the browser. Most importantly, it does all of this on the fly and requires only a few simple changes to your existing web pages.

He gives a before and after example of the things it can do - mainly combining multiple tags (like link and script) and their information into one. Check out its page on the Google Code site for more information.

0 comments voice your opinion now!
css javascript combine reduce load time css javascript combine reduce load time


NewsForge.com:
A DIY calendar control in PHP
January 26, 2007 @ 15:25:00

As a former ASP.Net coder, I've missed the convenience of Microsoft's built-in Calendar Control since I switched to doing Web site development in PHP. On a recent project I needed the ability to display a calendar with dates serving as hyperlinks to selected database items. I decided to use the opportunity to write some portable PHP code that I could use in other projects.

So started Donald McArthur's work on creating a simple, easy to use calendaring system to be used in a popup inside an application. He provides all the code you'll need - the PHP code and the HTML layout/functionality you'll need to get it working.

He helps you visualize the structure of the end result HTML table with a simpler version (three cells by five cells) and explains the date functions the code uses to figure out the dates and days of the selected month.

0 comments voice your opinion now!
diy calendar date time function control table diy calendar date time function control table



Community Events











Don't see your event here?
Let us know!


zendframework release cakephp job conference database developer application PEAR framework book PHP5 package zend security mysql ajax example code releases

All content copyright, 2008 PHPDeveloper.org :: info@phpdeveloper.org - Powered by the Solar PHP Framework