PHP Speed Tricks

Discussion in 'PHP' started by minnseoelite, Oct 14, 2006.

  1. #1
    I know PHP scripting already helps somewhat with page load speed but I was wondering if anyone had any tricks or tips specifically for making PHP sites using MySQL load faster. Here are the things I have already done.

    1. Making sure MySQL database has no overhead through the PHPmyadmin "Optimize Table" feature

    2. All javascript is served through the MySQL database

    Are there any really good tricks out there or scripts which will speed up websites coded in PHP and using Mysql.
     
    minnseoelite, Oct 14, 2006 IP
  2. Morishani

    Morishani Peon

    Messages:
    239
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Morishani, Oct 15, 2006 IP
  3. T0PS3O

    T0PS3O Feel Good PLC

    Messages:
    13,219
    Likes Received:
    777
    Best Answers:
    0
    Trophy Points:
    0
    #3
    What does JavaScript have to do with the Database?!

    Just optimize all your queries, learn how to use EXPLAIN.
     
    T0PS3O, Oct 15, 2006 IP
  4. daboss

    daboss Guest

    Messages:
    2,249
    Likes Received:
    151
    Best Answers:
    0
    Trophy Points:
    0
    #4
    i suspect he stores the javascript in a table and is put together by php to be served to the browser... ;) not sure why that he does that though - i'd put it into an include file instead...
     
    daboss, Oct 15, 2006 IP
  5. streety

    streety Peon

    Messages:
    321
    Likes Received:
    15
    Best Answers:
    0
    Trophy Points:
    0
    #5
    There are a whole host of things you can do to speed up your scripts.

    If you run your own server you can look into PHP accelerators. If you go to the PHP links page and go down about half way you'll see 5 links for PHP accelerators. APC and Zend Accelerator are probably the most well established.

    Whether you run your own server or not there are a whole host of things you can do to speed up your scripts. In many ways it is similar to SEO, it is all about testing. Don't go out fixing bottlenecks (those parts of your scripts which slow things down) until you have timed their execution. phpfreaks has a good tutorial on creating a timing class.

    Typically though you can usually see benefits by caching database queries if the results don't change frequently. The same goes for grabbing data from another server, an RSS feed for example (magpie which is a popular tool for grabbing an rss feed already handles caching) or in one of my recent projects where I wanted to grab the google pagerank for a site.

    Going back to your post I'm not sure why you would want to store javascript in a database, it typically doesn't change that much so an include file (as mentioned previously) would make more sense.
     
    streety, Oct 15, 2006 IP
  6. DrMalloc

    DrMalloc Peon

    Messages:
    130
    Likes Received:
    9
    Best Answers:
    0
    Trophy Points:
    0
    #6
    APC cache is great for tweaking, APD is good for finding bottlenecks in your code (you actually great a breakdown function-by-function for calls). Caching static HTML for all pages that aren't going to change takes a huge load off the server by not having to invoke the PHP interpreter each time. I'll chime in on the WTF over javascript stored in the database.
    http://www.dublish.com/articles/10.html also has some good tips.
     
    DrMalloc, Oct 15, 2006 IP
    streety likes this.
  7. chewbacca

    chewbacca Peon

    Messages:
    132
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #7
    Thanks DrMalloc, I lost that link a while ago and couldn't find it again until now. :)
     
    chewbacca, Oct 15, 2006 IP
  8. penagate

    penagate Guest

    Messages:
    277
    Likes Received:
    17
    Best Answers:
    0
    Trophy Points:
    0
    #8
    No, server-side scripting slows things down. It's important (in my opinion, anyway) to understand REST principles, and to make your server-side scripts behave as much like a collection of static resources as possible. Static is quick, dynamic is slow.

    On the topic of SQL: use parameterised prepared statements with a proper data access API such as PDO; PEAR::MDB2; or failing that, even mysqli. When supported by the DBMS, prepared statements can provide a decent performance boost as they do not have to be parsed and compiled every time they are called. Also look into moving data manipulation logic to the data layer using techniques such as stored procedures and transactions where appropriate.

    + 1.
    Remember, database access is slow! The best optimisation you can with a database is to avoid it altogether where possible. File system access is quick, and can be done by the user agent: which allows you the benefit of client-side caching as per proper HTTP. The less communication, the better. Store Javascript and CSS in their own files, .js and .css respectively, and somewhere a puppy will be born.

    In addition to those mentioned on that page, I'll add this: don't use echo or echo-like functions in a production environment. Close the <?php ... ?> blocks to output content, it's more efficient, and also better coding practice as it clearly separates template logic and document content.
     
    penagate, Oct 15, 2006 IP
  9. minnseoelite

    minnseoelite Peon

    Messages:
    845
    Likes Received:
    15
    Best Answers:
    0
    Trophy Points:
    0
    #9
    The reason the javascript is stored in the database is because the person who created the CMS for the site did it that way while my other site that i did has the javascript as an include. I would go change it but there are two places per page and over 2000 pages on the site and it would just take to long as i have multiple projects i am working on.
     
    minnseoelite, Oct 15, 2006 IP