There are no comments yet...Kick things off by filling out the form below.
One of the main reasons for the growing popularity of PHP is its elegant design and fast scripting – you can run complex calculations and procedures nearly instantly, and can scale large applications with multiple layers of logic relatively easily. As your web or software application becomes large, however, multiple database queries, server calls and files can slow down your load times. In order to help you improve the speed and efficiency of your app, this guide outlines some crucial ways to add some zest and speed back to your code:
While PHP has a flexible structure that allows for a variety of coding formats, you can often improve the performance of your application with a more direct approach. Streamlining your code with a more direct approach can lower the number of calculations, which can make a big difference in speed across large applications. Consider the case of a social networking application that pulls a list of friends from a database:
class friends {
public $friend = '';
public function setFriend($friend) {
$this->friend = $friend;
}
public function getFriend() {
return $this->friend;
}
}
In this structure, creating the friend class is less efficient than it would be to call the friend variable directly. Setting and getting the friend only adds another queue to the database without improving performance or code organization:
$friend = friend();
$friend->setFriend('friend');
echo $friend->getFriend();
With a simpler structure, you can make the code much cleaner:
$friend = friend(); $friend->connection = 'friend'; echo $friend->connection;
In PHP based applications, database queries are one of the most resource intensive calls to your server. While databases are designed to improve retrieval of information combining database queries can speed up the efficiency of your application overall. Building on the previous example, suppose we can to run a database query to get the name and relationship of a friend from a social network:
foreach ($FriendSet as $friends) {
$query = 'INSERT INTO friends (name,relationship) VALUES("' .
$friends[‘name'] . '", "' . $friends['relationship'] . '")';
mysql_query($query);
}
This produces a loop which adds each information element one at a time, meaning the procedure has to cycle through twice for each new data point. We can combine the entry into a single query to update the relationship in one fell swoop:
$FriendsData = array();
foreach ($FriendSet as $friends) {
$FriendsData[] = '("' . $friend[‘name'] . '", "' .
$friend['relationship'] . '")';
}
$query = 'INSERT INTO friends (name,relationship) VALUES ' .
implode(',', $FriendsData);
mysql_query($query);
In addition to cleaning up your PHP and mySQL code, you can further improve the performance of your app by using 3rd party tools and modules. One effective way to improve performance is through memcache, which makes it easier to cache data and objects in your server to make serving up information much easier. A version of the system is used by some of the largest database driven sites online. Selective use of tools such as memory buffer optimization and PHP code profiling can further improve your application performance.
There are no comments yet...Kick things off by filling out the form below.
| 1 | MyHosting - $4.00 USD |
| 2 | InMotion Hosting - $5.95 USD |
| 3 | WebHostingHub - $4.95 USD |
| 4 | JustHost - $3.95 CDN |
| 5 | iPage - $3.50 CDN |
| 6 | HostGator - $4.95 USD |
| 7 | FatCow - $3.67 USD |
| 8 | GreenGeeks - $4.95 USD |
| 9 | BlueHost - $6.95 USD |
| 10 | GoDaddy - $4.11 CDN |