Hi friends ,
PHP is becoming very popular scripting language and you may know this from the prabhu’s article published in this post.
It is easy for anyone to program with the help of PHP,but most the people failed in the speed (ie optimazation) section .
If your site is loading slowly then you will definitely lose the traffic.
So i am giving few tips on how to improve the performance of PHP as well as how to write the code effectively.

Use caching:
Making use of a caching module, such as “Memcache”, or a templating system which supports caching, such as Smarty, can help to improve the performance of your website by caching database results and rendered pages.

Use ini_Set in all PHP files:
Since we are not going to execute script in all the pages for long time and also we wont use long query in all the pages.
So ,always use the ini_set in each and every pages.
ini_set

Use output buffering:

PHP uses a memory buffer to store all of the data that your script tries to print. This buffer can make your pages seem slow, because your users have to wait for the buffer to fill up before it sends them any data. Fortunately, you can make some changes that will force PHP to flush the output buffers sooner, and more often, making your site feel faster to your users.

Don’t copy variables for no reason:
Sometimes PHP novices attempt to make their code “cleaner” by copying predefined variables to variables with shorter names before working with them. What this actually results in is doubled memory consumption, and therefore, slow scripts. In the following example, imagine if a malicious user had inserted 512KB worth of characters into a textarea field. This would result in 1MB of memory being used!

$description = strip_tags($_POST['description']);
echo $description;

There’s no reason to copy the variable above. You can simply do this operation inline and avoid the extra memory consumption:
echo strip_tags($_POST['description']);


Avoid doing SQL queries within a loop:

A common mistake is placing a SQL query inside of a loop. This results in multiple round trips to the database, and significantly slower scripts. In the example below, you can change the loop to build a single SQL query and insert all of your users at once.

foreach ($userList as $user) {
$query = ‘INSERT INTO users (first_name,last_name) VALUES(“‘ . $user['first_name'] . ‘”, “‘ . $user['last_name'] . ‘”)’;
mysql_query($query);
}

Produces:
INSERT INTO users (first_name,last_name) VALUES(“John”, “Doe”)

Instead of using a loop, you can combine the data into a single database query.
$userData = array();
foreach ($userList as $user) {
$userData[] = ‘(“‘ . $user['first_name'] . ‘”, “‘ . $user['last_name'] . ‘”)’;
}
$query = ‘INSERT INTO users (first_name,last_name) VALUES’ . implode(‘,’, $userData);
mysql_query($query);Produces:
INSERT INTO users (first_name,last_name) VALUES(“John”, “Doe”),(“Jane”, “Doe”)…

Use single-quotes for long strings:

The PHP engine allows both single-quotes and double-quotes for string variable encapsulation, but there are differences! Using double-quotes for strings tells the PHP engine to read the string contents and look for variables, and to replace them with their values. On long strings which contain no variables, that can result in poor performance.

$output = “This is the content for a very long article
which is a few hundred lines long
and goes on and on and on

The End”;

Changing the double-quotes to single-quotes prevents the PHP engine from parsing this string in an attempt to expand variables which, in this example, don’t exist:

$output = ‘This is the content for a very long article
which is a few hundred lines long
and goes on and on and on

The End’;

Few more tips:

->Upgrade your PHP version.

->Use “echo” is faster than “print “.

->Use “Unset” or “null” your variables to free memory, especially large arrays

->Use require() instead of require_once() .

->Use full paths in includes and requires, less time spent on resolving the OS paths.

->Use $_SERVER['REQUEST_TIME'] is instead of time()

->Use of error supression (@) is very slow.

->Use of $row['id'] is 7 times faster than $row[id].

->Use of error messages are expensive.

->Use of count() in the for forloop is expensive(The count() function gets called each time)
->Use of “else if” statements are faster than “switch/case” statements.

->Use <?php … ?> tags and dont use short tags.

->Use of “++$i” is faster than “$i++”.

->Avoid magic like __get, __set, __autoload.

->If a method can be static, declare it static. Speed improvement is by a factor of 4.

3 Aug, 2009  |   Written by vetrivel  |  under General

We know that 36 percent of the scientists at NASA are now Indians, but did you know that India will become number 1 source of PHP developers soon. In a research report released by PHPClasses, number of PHP developers in India has been steadily increasing in the last few years.And soon we will replace the current United States as the main resource for the PHP development.

If we look at the figures regarding the users in PHPClasses site US-based developers stands at the top with 11.8% of the total number of users followed by INIDA with a percentage of 10.5% running behind in the race are Brazil and Germany with 5.22% and 4.66%.An interesting fact to note is that few years back USA ruled the charts with 20% of all users whereas INDIA account for only 3%.

When we look up at this drastic change it is not possible to locate at the exact reason why this happened.But the fact that the developing a site in INDIA is quite less than what the US and the European market charges can not be denied.If the growth remains in the same pace we will have lots of companies developing php based sites and products like X-cart, Magento, OSCommerce etc. However the report also states that the number of certified professionals in INDIA are very less compares to the US and European countries.

30 Jul, 2009  |   Written by prabhu.pandian  |  under Business, Ecommerce, General