It examines the result from a query and returns an analysis of the results that suggests optimal data types for each column. To obtain this analysis, append PROCEDURE ANALYSE to the end of a SELECT statement.
For Example:
SELECT col1, col2 FROM table1 PROCEDURE ANALYSE();
SELECT * FROM table1 PROCEDURE ANALYSE();
Quite common task during schema review is to find the optimal data type for the column value - for example column is defined as INT but is it really needed or may be SMALLINT or even TINYINT will do instead. Read the post in mysqlperformanceblog explained in more detail.
PROCEDURE ANALYSE() can be a double edged tool. In the first it will help you to find the optimal data type for column. In the second case it had no idea you needed bigger values and gave you a recommendation based on bad data. Like most tools, PROCEDURE ANALYSE() needs to be used properly to get the desired results.
Syntax and more info here.
Tuesday, May 12, 2009
Search & replace in files using php
Very nice post from Sameer, in his blog code-diesel explaining how to search and replace in file using PEAR library File_SearchReplace.
Below are link explaining how to install PEAR.
Install PEAR on Windows
Install PEAR on LINUX
Read more about File_SearchReplace with example here
Below are link explaining how to install PEAR.
Install PEAR on Windows
Install PEAR on LINUX
Read more about File_SearchReplace with example here
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()
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
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
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;
}
?>
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.
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.
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.
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.
Subscribe to:
Posts (Atom)