Friday, May 08, 2009

PHP 5.3 upgrading notes

Hi all upgrading to php 5.3 just go through the php 5.3 upgrading notes on wiki.php.net, lots of changes done, lots of new classes,method also function added and extension added and removed. List of upgrading notes is huge go through it. Below are few quick notes:

Reserved word: GOTO,NAMESPACE,CLOSURE are now reserved word in PHP, Make correction to your programs or else php will trow Fatal Error while parsing the script.

Functions affecting backwards compatibility:
* var_dump() output with objects.
* session_start() now returns false if session startup fails for some reason.
* opendir(), scandir() and dir() now use the default context if no context passed.
* The new mysqlnd library necessitates using MySQL's newer 41 byte password format. Continued use of the old 16 byte passwords will cause mysql_connect() to produce the following error message: “mysqlnd cannot connect to MySQL 4.1+ using old authentication.” No need to worry if you are using MySQL version >= 4.1, Prior to MySQL 4.1, password hashes computed by the PASSWORD() function are 16 bytes long.

Bye Bye windows 98 or NT4: The minimum Windows versions are now windows 2000/XP.

Libraries added: mysqlnd (optional replacement for libmysql)

Extension Changes Causing Incompatibilities:
"Session" - Sessions would no longer succeed to store session-files in ”/tmp” path if open_basedir restriction is enabled, and ”/tmp” is not explicitly added to allowed paths list (special treatment of ”/tmp” was added in 5.2.2, but was not documented)

Deprecated:
* define_syslog_variables() now issues E_DEPRECATED
* all ereg functions now issues E_DEPRECATED (note that not all of them are prefixed with ereg)

New functions:

Array

* array_replace()
* array_replace_recursive()

Date

* date_add()
* date_sub()
* date_diff()
* date_parse_from_format()
* date_create_from_format()
* date_get_last_errors()
* timezone_version_get()

Filesystem

* parse_ini_string()

MySQLi

* mysqli_fetch_all()
* mysqli_get_connection_stats()
* mysqli_poll()
* mysqli_reap_async_query()

Tuesday, May 05, 2009

Submitting Sitemaps using robots.txt

What are Sitemaps?

Sitemaps are an easy way for webmasters to inform search engines about pages on their sites that are available for crawling. In its simplest form, a Sitemap is an XML file that lists URLs for a site along with additional metadata about each URL (when it was last updated, how often it usually changes, and how important it is, relative to other URLs in the site) so that search engines can more intelligently crawl the site.

You can tell Google and other search engines about your Sitemap by using robot.txt

Read file in php

Really nice post with example explaining how we can read large size file using php.

Retrieving original url from short url using PHP and CURL

Good post explaining how to get back original url from short url.

expanding short url to original url using PHP and CURL

Monday, May 04, 2009

Luhn algorithm for validating credit cards

The Luhn algorithm also known as the “modulus 10″ or “mod 10″ algorithm, is a checksum formula which can be used to validate credit card numbers. Developed in the 1950’s by IBM scientist Hans Peter Luhn and described in U.S. Patent 2,950,048. A PHP implementation is shown below.


function LuhnCheck($strDigits)
{
$sum = 0;
$alt = false;
for($i = strlen($strDigits) - 1; $i >= 0; $i--)
{
if($alt)
{
$temp = $strDigits[$i];
$temp *= 2;
$strDigits[$i] = ($temp > 9) ? $temp = $temp - 9 : $temp;
}
$sum += $strDigits[$i];
$alt = !$alt;
}
return $sum % 10 == 0;
}

?>

Web scraping tutorial

Web scraping (or Web harvesting, Web data extraction) is a computer software technique of extracting information from websites.

I got a freelance work to extract all the hotel information in UK of some city from yellow pages, I wrote a simple php script which uses curl to get the data and parse it using regular expression and extract the require data and populate db, sorry was not aware probably ignored policies.

Now there is a PHP library that facilitates the process of creating web scrapers called Simplehtmldom. More information can be found here.

Checking coding standards with PHP_Codesniffer

PHP_CodeSniffer is a PHP5 script that tokenises and "sniffs" PHP and JavaScript code to detect violations of a defined coding standard. It is an essential development tool that ensures your code remains clean and consistent. It can also help prevent some common semantic errors made by developers.

I was really behind this in my previous company, i want to make sure everyone follows the coding standard, with this tool i am sure that problem is solved.

You can also define your own coding standard, it can be integrated with Subversion.

More detailed information with installation and example can be found here.

Load testing

http_load is a simple load testing tool.

http_load is a useful HTTP benchmarking utility that lets you run multiple http fetches in parallel to test the throughput of your web server. It gives you a rough idea of how many bytes a server can serve in a predetermined time.

Detailed information with example and download link can be found here.

Note: I didn't test it.

Tuesday, April 28, 2009

PHP 5.3 features

I was just going through the interview of Lukas Kahwe Smith(Release manager php.net), He was explaining the key features we need to look out in PHP 5.3. In all the feature i am keen to use the feature lambda functions and closures and also PHAR.
About lambda function and closure i have already posted.
In this post lets look at PHAR, In the interview Lukas didn't explain in depth about it just mentioned PHAR is the result of a "proof of concept" PEAR package called "PHP_Archive".

I found an very good article on net about PHAR with an example.

Monday, April 27, 2009

Where is the include coming from?

This is the post if you are interested to know how the flow of code is which file is included from were, here is a post with example of few of framework. I like it interesting post :)

Here a link.