Hi all I am kinda new to PHP and MySQL but I was wondering if there are any tricks or free scripts out there specifically designed to speed up websites coded in PHP and using a MySQL database.
| SitePoint Sponsor |


Hi all I am kinda new to PHP and MySQL but I was wondering if there are any tricks or free scripts out there specifically designed to speed up websites coded in PHP and using a MySQL database.
Zend offers some products that are specifically used to improve the performance of PHP applications.
http://www.zend.com/products/zend_optimizer
In our tests, the Zend Optimizer doesn't actually speed up script execution - it actually slows it down.
The best way to speed up scripts is to ensure they're coded efficiently - checking loops, function calls, use of variables. Simple things like using ' instead of " can help in a large application. Also, the hardware the script will run on has an effect - upgrade the server memory where necessary and search around for optimisation tips for Apache and MySQL.
Contrary to popular belief double quotes are in fact faster by quite some amount.Originally Posted by Olate
Location: Alicante (Spain)... Hot and Sunny...
Texas Holdem Poker Probability Calculator | DNS test
Avatars | English Spanish Translation | CAPTCHA with audio
Email | PHP scripts | Cruft free domain names | MD5 Cracker





How are double quotes faster than single quotes?Originally Posted by bokehman
![]()
AskItOnline.com - Need answers? Ask it online.
Create powerful online surveys with ease in minutes!
Sign up for your FREE account today!
Follow us on Twitter





You'll find the greatest improvements through improving your code.Originally Posted by minnseoelite
Make your algorithms as efficient as possible. unset() variables you aren't using anymore, etc.etc.
The BIGGEST thing is make your algorithms efficient!
AskItOnline.com - Need answers? Ask it online.
Create powerful online surveys with ease in minutes!
Sign up for your FREE account today!
Follow us on Twitter
It's a fact. Here's a link to my benchmark script and here's the code so you can study it:Originally Posted by triexa
Real efficiency is to be found in writing code with good logic rather than mucking about worrying about inconsquential savings due to what types of quotes are used in string literals.PHP Code:<?php
header("Content-Type: text/plain");
function no_string()
{
$start = microtime(TRUE);
return(microtime(TRUE) - $start);
}
function single_quote()
{
$start = microtime(TRUE);
$string = 'This is a test. It is only a test. Testing 1, 2, 3. '.
'This has been a test. It was only a test. 3, 2, 1, the end.';
return(microtime(TRUE) - $start);
}
function double_quote()
{
$start = microtime(TRUE);
$string = "This is a test. It is only a test. Testing 1, 2, 3. ".
"This has been a test. It was only a test. 3, 2, 1, the end.";
return(microtime(TRUE) - $start);
}
function heredoc_str()
{
$start = microtime(TRUE);
$string = <<<EOD
This is a test. It is only a test. Testing 1, 2, 3.
This has been a test. It was only a test. 3, 2, 1, the end.
EOD;
return(microtime(TRUE) - $start);
}
$seed = microtime(TRUE); // because first call is always slow
$methods = array('no_string', 'single_quote', 'double_quote', 'heredoc_str');
for($ix=0; $ix<200; $ix++)
{
array_rand($methods);
foreach($methods as $method)
{
$times[$method][] = call_user_func($method);
}
}
$methods = array('no_string', 'single_quote', 'double_quote', 'heredoc_str');
$error = array_shift($methods);
$error = array_sum($times[$error]) / count($times[$error]);
foreach($methods as $method)
{
$averages[$method] = sprintf("%01.8f", (array_sum($times[$method]) / count($times[$method]))-$error);
}
/*foreach($averages as $k => $v)
{
$averages[$k] = $v - $error;
}*/
echo "Averages (seconds):\n";
print_r($averages);
/*
echo "\nRaw Data:\n";
print_r($times); // show raw data
*/
?>
Location: Alicante (Spain)... Hot and Sunny...
Texas Holdem Poker Probability Calculator | DNS test
Avatars | English Spanish Translation | CAPTCHA with audio
Email | PHP scripts | Cruft free domain names | MD5 Cracker





Great, I have always used double quotes. But in many forums I have found it mentioned a few times that single quotes performs best when it comes to doing variables and other functions and things in php.
I have since for the last year or some been slowly replace parts of my scripts with single quotes instead of double quotes.
It looks as if I have to start changing them back again.
wow bokehman. interesting.
is there any PHP code reviewer scripts out there?
like cleancss.com etc etc.
something that can review your php code & give you suggestions as to speeding it up?
alternatively do any people offer services of actually cleaning up & improving efficiency of php pages?
thanks!
» azuranz
Confucius says... man who fight with wife all day, get no piece at night


In my experience, the biggest bottleneck is MySQL. Make sure your queries are efficient before unnecessarily over-auditing your php code.





Why? So your app can run 0.005% faster?It looks as if I have to start changing them back again.
When performance tuning spend your time where there will be the most pay off. Database queries are one thing, anything else "heavy" like image, email or PDF processing is also going to be much slower than parsing a string with single or double quotes.
Test your script first (Xdebug is a good way) so you can actually make purposeful changes instead of just going through the motions.
Getting a 1 or 2% performance increase on a script isn't normally worth while because those gains could be undone by a small increase in traffic.
Similarly tweaking some rarely used features is much less worthwhile than improving code that is called and used a lot.
Bookmarks