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

Mohamed Said:
Laravel/MySQL JSON documents faster lookup using generated columns
Aug 22, 2017 @ 15:55:05

Mohamed Said has an interesting post to his site showing how to use computed columns for faster lookups in a MySQL database containing JSON documents.

Laravel 5.3 is shipped with built-in support for updating and querying JSON type database fields, the support currently fully covers MySQL 5.7 JSON type fields updates and lookups.

He includes an example of using the Eloquent DB handling to search for the data in the JSON and the results. He links to more information about the feature, following it up with an example of the main topic: computed columns. In it he shows how to create (on the SQL side) a generated/computed column that allows for easier extraction of the data directly from the JSON. This makes it even simpler to get the data just as you would in a normal select. He also includes an example of creating it via the Schema functionality in the database migrations.

tagged: mysql json column lookup computed generated sql data laravel tutorial

Link: https://themsaid.com/laravel-mysql-json-colum-fast-lookup-20160709

Nikita Popov:
PHP's new hashtable implementation
Dec 26, 2014 @ 16:20:10

In his latest post Nikita Popov gives a detailed look at PHP's new hashtable implementation and what kinds of improvements it offers over the previous methods. The "hashtable" handling is how the language references array values created during the execution of a script.

About three years ago I wrote an article analyzing the memory usage of arrays in PHP 5. As part of the work on the upcoming PHP 7, large parts of the Zend Engine have been rewritten with a focus on smaller data structures requiring fewer allocations. In this article I will provide an overview of the new hashtable implementation and show why it is more efficient than the previous implementation.

He starts with an introduction to the concept of hashtables, describing them as "ordered dictionaries" of key/value pairs that (internally) reference values in an array. He looks at the old method PHP used to make these links and how the new version, with the help of zval handling, is different. He talks about how it handles the order of elements, does lookups and the introduction of "packed" and "empty" hashtables. He ends the post with a look at this new implementation's memory utilization and what kind of performance gains we can expect with its introduction in PHP7.

tagged: hashtable array implementation php7 performance memory lookup

Link: http://nikic.github.io/2014/12/22/PHPs-new-hashtable-implementation.html

Michael Dowling:
Favor Hash Lookups Over Array Searches
Mar 21, 2014 @ 15: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.

tagged: 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
Jul 01, 2010 @ 16: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).

tagged: dns lookup tutorial hostname

Link:

Sameer Borate's Blog:
Geographical information lookup using GeoNames
Apr 19, 2010 @ 13: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)

tagged: geographical geonames webservice lookup tutorial

Link:

Ken Guest's Blog:
A response to "Better Postal/Zip Code Validation Method for CakePHP 1.2"
Dec 17, 2009 @ 17: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.

tagged: response zipcode postal validation pear lookup

Link:

Debuggable Blog:
How To Save Half A Second On Every CakePHP Request
Feb 27, 2009 @ 18: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.

tagged: half second request performance cakephp framework reverse route lookup

Link:

Havard Eide's Blog:
phpm (a vim PHP function lookup tool)
Jan 02, 2009 @ 21: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.

tagged: phpm function lookup tool source xml phpdocumentor

Link:

PHPBuilder.com:
Using cURL with PHP
Feb 03, 2007 @ 00: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.

tagged: curl tutorial lookup protected posting ftp curl tutorial lookup protected posting ftp

Link:

PHPBuilder.com:
Using cURL with PHP
Feb 03, 2007 @ 00: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.

tagged: curl tutorial lookup protected posting ftp curl tutorial lookup protected posting ftp

Link:


Trending Topics: