RE: [PHP] High bandwidth application tips
| From: | Chris Shiflett | Date: | Thu, 06 Nov 2003 05:24:41 +0000 |
| Subject: | RE: [PHP] High bandwidth application tips | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-168674@lists.php.net to get a copy of this message | ||
--- Wouter van Vliet <wouter@springt.nl> wrote:
> One time I had this script somebody else wrote. About 1000 lines, a
> complete CMS in one file. It if'ed on simple $_GET vars about 10 times,
> by opening a new if statement each and every time. After I changed this
> to if ($_GET['p'] == 'one') { .. } elseif ($_GET['p'] ==
> 'two') { .. };
> and so on the script became TWO SECONDS faster.
Another minor performance tip to add to this is to use $p in your
conditional statements rather than $_GET['p']. Of course, you should
filter this data also, but try something like this:
if ($_GET['p'] is valid data)
{
$p = $_GET['p'];
}
When you use $p in the rest of the script, you save PHP the small
discovery time required for $_GET['p']. If you have many conditional
statements, this minor improvement can be amplified slightly, and if you
have many users (a few million a day, for example), this improvement is
further amplified.
Hope that helps.
Chris
=====
My Blog
http://shiflett.org/
HTTP Developer's Handbook
http://httphandbook.org/
RAMP Training Courses
http://www.nyphp.org/ramp