SitePoint Sponsor

User Tag List

Results 1 to 11 of 11
  1. #1
    SitePoint Addict
    Join Date
    Nov 2005
    Location
    Minnesota, United States
    Posts
    236
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Speed Up Your PHP Site

    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.

  2. #2
    SitePoint Wizard bronze trophy Kailash Badu's Avatar
    Join Date
    Nov 2005
    Posts
    2,561
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Zend offers some products that are specifically used to improve the performance of PHP applications.
    http://www.zend.com/products/zend_optimizer

  3. #3
    SitePoint Addict Olate's Avatar
    Join Date
    Apr 2003
    Location
    UK
    Posts
    252
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    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.

  4. #4
    Keep it simple, stupid! bokehman's Avatar
    Join Date
    Jul 2005
    Posts
    1,933
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Olate
    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.
    Contrary to popular belief double quotes are in fact faster by quite some amount.

  5. #5
    SitePoint Wizard triexa's Avatar
    Join Date
    Dec 2002
    Location
    Canada
    Posts
    2,476
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by bokehman
    Contrary to popular belief double quotes are in fact faster by quite some amount.
    How are double quotes faster than single quotes?
    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

  6. #6
    SitePoint Wizard triexa's Avatar
    Join Date
    Dec 2002
    Location
    Canada
    Posts
    2,476
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by minnseoelite
    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.
    You'll find the greatest improvements through improving your code.

    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

  7. #7
    Keep it simple, stupid! bokehman's Avatar
    Join Date
    Jul 2005
    Posts
    1,933
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by triexa
    How are double quotes faster than single quotes?
    It's a fact. Here's a link to my benchmark script and here's the code so you can study it:
    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
    */

    ?>
    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.

  8. #8
    SitePoint Wizard
    Join Date
    Nov 2003
    Location
    United Kingdom
    Posts
    2,118
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    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.

  9. #9
    SitePoint Enthusiast azuranz's Avatar
    Join Date
    Sep 2005
    Location
    Bermuda Triangle
    Posts
    98
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    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

  10. #10
    SitePoint Addict
    Join Date
    Jun 2005
    Posts
    260
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    In my experience, the biggest bottleneck is MySQL. Make sure your queries are efficient before unnecessarily over-auditing your php code.

  11. #11
    SitePoint Wizard cranial-bore's Avatar
    Join Date
    Jan 2002
    Location
    Australia
    Posts
    2,634
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    It looks as if I have to start changing them back again.
    Why? So your app can run 0.005&#37; faster?

    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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •