This is a discussion on PHP Optimization Tips within the PHP Programming forums, part of the Web Development category; Hi, Your PHP scripts are recompiled every time unless the scripts are cached. Install a PHP caching product to typically ...
| |||||||
| Register | FAQ | Members List | Calendar | Mark Forums Read |
| |||
| Hi, Your PHP scripts are recompiled every time unless the scripts are cached. Install a PHP caching product to typically increase performance by 25-100% by removing compile times.
__________________ Regards, Senraj.A |
| Sponsored Links |
| |||
| Hi, When echoing strings it's faster to separate them by comma instead of dot. Note: This only works with echo, which is a function that can take several strings as arguments.
__________________ Regards, Senraj.A |
| |||
| Hi, Surrounding your string by ' instead of " will make things interpret a little faster since php looks for variables inside "..." but not inside '...'. Of course you can only do this when you don't need to have variables in the string.
__________________ Regards, Senraj.A |
| |||
| Hi, A function call with one parameter and an empty function body takes about the same time as doing 7-8 $localvar++ operations. A similar method call is of course about 15 $localvar++ operations.
__________________ Regards, Senraj.A |
| |||
| Hi,
__________________ Regards, Senraj.A |
| |||
| Hi, Just declaring a global variable without using it in a function also slows things down (by about the same amount as incrementing a local var). PHP probably does a check to see if the global exists.
__________________ Regards, Senraj.A |
| |||
| Hi, Method invocation appears to be independent of the number of methods defined in the class because I added 10 more methods to the test class (before and after the test method) with no change in performance.
__________________ Regards, Senraj.A |
| |||
| Hi,
__________________ Regards, Senraj.A |
| |||
| Hi, Achieving High Performance When we talk about good performance, we are not talking about how fast your PHP scripts will run. Performance is a set of trade offs between scalability and speed. Scripts tuned to use fewer resources might be slower than scripts that perform caching, but more copies of the same script can be run at one time on a web server.
__________________ Regards, Senraj.A |
| |||
| Hi, Achieving High Performance In the example below, A.php is a sprinter that can run fast, and B.php is a marathon runner than can jog forever at the nearly the same speed. For light loads, A.php is substantially faster, but as the web traffic increases, the performance of B.php only drops a little bit while A.php just runs out of steam. ![]()
__________________ Regards, Senraj.A |
| |||
| Hi, Achieving High Performance Let us take a more realistic example to clarify matters further. Suppose we need to write a PHP script that reads a 250K file and generates a HTML summary of the file. We write 2 scripts that do the same thing: hare.php that reads the whole file into memory at once and processes it in one pass, and tortoise.php that reads the file, one line at time, never keeping more than the longest line in memory. Tortoise.php will be slower as multiple reads are issued, requiring more system calls.
__________________ Regards, Senraj.A |
| |||
| Hi, Achieving High Performance Hare.php requires 0.04 seconds of CPU and 10 Mb RAM and tortoise.php requires 0.06 seconds of CPU and 5 Mb RAM. The server has 100 Mb free actual RAM and its CPU is 99% idle. Assume no memory fragmentation occurs to simplify things. At 10 concurrent scripts running, hare.php will run out of memory (10 x 10 = 100). At that point, tortoise.php will still have 50 Mb of free memory. The 11th concurrent script to run will bring hare.php to its knees as it starts using virtual memory, slowing it down to maybe half its original speed; each invocation of hare.php now takes 0.08 seconds of CPU time. Meanwhile, tortoise.php will be still be running at its normal 0.06 seconds CPU time.
__________________ Regards, Senraj.A |
| |||
| Hi, In the table below, the faster php script for different loads is in bold: HTML Code: Connections CPU seconds required to satisfy 1 HTTP request CPU seconds required to satisfy 10 HTTP requests CPU seconds required to satisfy 11 HTTP requests hare.php 0.04 0.40 0.88 (runs out of RAM) tortoise.php 0.06 0.60 0.66 As the above example shows, obtaining good performance is not merely writing fast PHP scripts. High performance PHP requires a good understanding of the underlying hardware, the operating system and supporting software such as the web server and database.
__________________ Regards, Senraj.A |
| |||
| Hi, Optimize table: This is useful when the table contains overheads. After massive deletions of rows or length changes for VARCHAR fields, lost bytes remain in the table. PhpMyAdmin warns us in various places (for example, in the Structure view) if it feels the table should be optimized. This operation is a kind of defragmentation for the table. In MySQL 4.x, this operation works only on tables in the MyISAM, Berkeley (BDB), and InnoDB engines. In MySQL 5.x, it works only on tables in the MyISAM, InnoDB, andARCHIVE engines.
__________________ Regards, Senraj.A |
| |||
| Hi,
__________________ Regards, Senraj.A |
![]() |
| Thread Tools | |
| Display Modes | |
| |
LinkBacks (?)
LinkBack to this Thread: http://www.discussweb.com/php-programming/4357-php-optimization-tips.html | |||
| Posted By | For | Type | Date |
| The Storyteller | This thread | Refback | 11-30-2007 07:09 AM |
| del.icio.us/subscriptions/KoerPoiss | This thread | Refback | 11-30-2007 06:47 AM |
| Planet PHP Japan | This thread | Refback | 11-30-2007 04:35 AM |
Similar Threads | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| All You Need for Search Engine Optimization (SEO) | vozduhh | Search Engine Optimization | 1 | 02-20-2008 11:40 AM |
| SEO optimization question.? | navjeet | Search Engine Optimization | 1 | 09-04-2007 11:54 AM |
| Image Alt Tag Optimization Tips | vadivelanvaidyanathan | Search Engine Optimization | 0 | 03-30-2007 03:02 AM |
| Title Tag Optimization Tips | vadivelanvaidyanathan | Search Engine Optimization | 0 | 03-30-2007 02:58 AM |
| SEO Optimization - Page Title | drecko | Search Engine Optimization | 2 | 02-19-2007 01:28 AM |