News Feed
Sections




News Archive
feed this:

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

Michael Dowling:
Favor Hash Lookups Over Array Searches
March 21, 2014 @ 10:47:34

Michael Dowling has a recent post to his site comparing the performance of hash lookups versus array searches.

A common programming requirement is to match a string against a set of known strings. For example, let's say you were iterating over the words in a forum post and testing to see if a word is in a list of prohibited words. A common approach to this problem is to create an array of the known prohibited words and then use PHP's in_array() function to test if the string is found in the list. However, there's a simple optimization you can make to significantly improve the performance of the algorithm.

He includes two pieces of sample code - one showing the searching of an array using in_array and the other running an isset to locate a key. He points out that the in_array method is quite a bit slower than the hash (key) lookup and includes a benchmark script to prove it.The results are pretty clear, with the hash lookup coming in about 480% faster than the in_array. He also points out that as the size of the strings you're comparing grows, the performance of in_array drops even more.

0 comments voice your opinion now!
hash lookup search array inarray benchmark

Link: http://mtdowling.com/blog/2014/03/17/hash-lookups-over-array-search/

Vanessa Vasile's Blog:
Using PHP to Perform DNS Lookups
July 01, 2010 @ 11:37:51

In a handy little post to her blog today Vanessa Vasile has an example of how to use built-in PHP functions to perform DNS lookups in your scripts.

PHP has a couple DNS functions you can use to perform record lookups. Most of us are familiar with the two basic ones - gethostbyname() and gethostbyaddr(), both of which perform a single function '" returning a hostname or IP address.

She also mentions the gethostbynamel and dns_get_record functions that can give you even more insight into the current DNS of a given domain (even returning only record-type specific information).

0 comments voice your opinion now!
dns lookup tutorial hostname


Sameer Borate's Blog:
Geographical information lookup using GeoNames
April 19, 2010 @ 08:25:01

New on his blog today Sameer Borate has posted a new tutorial about using the GeoNames web service to look up geographical information about your visitors (and help with targeting the experience just for them).

Geographical information integration is rapidly becoming an integral part of many websites. People use geographic data for a wide variety of applications. From location based content targeting, censoring information by geographic areas to analyzing website traffic by region. It is surprising how much free geographic information is available on the web. GeoNames is one such service.

The database is released under a Creative Commons license, so it's available to all and getting the libraries installed to use it is a single "pear install" command away. He includes code showing how to make a sample search for cities, countries and "neighbors" as well as just performing a generic search off the data. He also throws in a method for accessing the information via jQuery (an ajax call)

0 comments voice your opinion now!
geographical geonames webservice lookup tutorial


Ken Guest's Blog:
A response to "Better Postal/Zip Code Validation Method for CakePHP 1.2"
December 17, 2009 @ 11:14:53

In response to a different post he read on a postal/zip code validation topic, Ken Guest has points out other resources that can be used to accomplish the same sort of thing and already exist.

I drew attention to two things. The first is that there are Validation packages in PEAR, including the main Validate class and all the Validate_xx subclasses such as Validate_US, Validate_CA and some 22 others). The second item I drew Jamie's attention to is that his validation code counts a zip code of "00000' as valid, when the USPS zip code look up tool correctly (and they should know!) identifies that code as invalid.

He wholeheartedly opposes the "Not Invented Here" syndrome that developers (with a hefty dose of framework developers included) seem to have.

1 comment voice your opinion now!
response zipcode postal validation pear lookup


Debuggable Blog:
How To Save Half A Second On Every CakePHP Request
February 27, 2009 @ 12:09:51

CakePHP users might want to listen to this suggestion from Tim Koschutzki on the Debuggable blog - he wants to help you save a half second on each request.

There are several ways to improve the performance of your CakePHP application. [...] Any performance improvement that does not effect how data is retrieved, stored and cached is welcome. If it affects your entire site and not only parts of it, it's all the better.

The performance boost comes in the form of an update to CakePHP's reverse route lookup functionality. Normally a lookup would have to be parsed and resolved back to their original location. They figured a bit faster way around it though - breaking the reverse routing feature for the sake of speed. The code for the hack is included in the post.

0 comments voice your opinion now!
half second request performance cakephp framework reverse route lookup


Havard Eide's Blog:
phpm (a vim PHP function lookup tool)
January 02, 2009 @ 15:34:02

Havard Eide shares a tool he originally created to do function lookups when in vim - phpm:

4 years ago I wrote a small program called phpm that I used for php function lookup when coding in vim. since then I've crossed over to ZendStudio and I'm now using that for my everyday work. But: every now and then I've had requests regarding phpm and if I can't digg up the sources, and I've said: "sorry, but those are lost". Until today: I went through a old HD, digging through backups and files: and suddenly phpm resurfaced!

He's included the links to the three things you'll need to get it working - the phpm file itself, XML required by it and an optional phpdocumentor template to create the output file.

0 comments voice your opinion now!
phpm function lookup tool source xml phpdocumentor


PHPBuilder.com:
Using cURL with PHP
February 02, 2007 @ 18:41:00

On PHPBuilder.com today, there's a new tutorial spotlighting the use of the cURL library with PHP:

cURL is one of the most powerful PHP extensions. It stands for Client URL, and allows you to communicate with other servers using a wide range of protocols. Perhaps that sounds fairly uninteresting, but give it some more thought.

As food for thought, they give a few examples of the use of this handy library - a script to look up the meaning of a word, how to access password protected pages, getting the information about a file from a remote server, posting to a remote script, and FTPing a file to a remote server. This flexible library allows all of these without making things overly complex and unmanageable.

You can check out the full list of features for the extension on this page of the PHP manual.

0 comments voice your opinion now!
curl tutorial lookup protected posting ftp curl tutorial lookup protected posting ftp


Joshua Eichorn's Blog:
HTML_AJAX Wordpress Plugin Tutorial
June 27, 2006 @ 06:05:20

Joshua Eichorn has found a tutorial someone else has written on creating a stock lookup plugin for WordPress with his HTML_AJAX package.

The only problem I see is the code won't work in PHP5 since introspection will return the method name as GetQuote instead of getquote.

He gives the code changes you'll need to make to get it all working in your PHP5 installation, and includes another option as well - registering all of the functions you want to use instead of just automagically using them.

1 comment voice your opinion now!
html_ajax pear package wordpress stock lookup plugin tutorial html_ajax pear package wordpress stock lookup plugin tutorial



Community Events





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


bugfix voicesoftheelephpant opinion community podcast laravel list api release framework language deployment library series package interview tips introduction install symfony

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