SitePoint Sponsor

User Tag List

Results 1 to 8 of 8
  1. #1
    SitePoint Guru hifigrafix's Avatar
    Join Date
    Oct 2005
    Location
    Nashville, TN
    Posts
    628
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Code Optimization

    Greetings,

    I've been googling for "PHP Optimization" and came across a link that is pretty helpful:

    http://ilia.ws/archives/12-PHP-Optimization-Tricks.html

    Anyone else got some optimization resources?

    I'm self-taught (like 99% of php developers) and since most of my knowledge came from tutorials I'm sure I missed quite a bit. Not like I do enterprise level scripting but it's nice to know how to get the most out of your code.

    jw

  2. #2
    SitePoint Wizard HarryR's Avatar
    Join Date
    Dec 2004
    Location
    London, UK
    Posts
    1,376
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Most of these things aren't going to have any major impact on the speed of your code unless you're doing a huge amount of them.

    Basically I'd follow a few of these more generally:
    • Avoid nested loops and double-check that everything you're doing in a loop is optimized.
    • Avoid using regular expressions for everything where there are native functions that do the same.
    • Make sure anything which contacts an external resource (e.g. database server) is given careful attention.

  3. #3
    SitePoint Wizard silver trophy kyberfabrikken's Avatar
    Join Date
    Jun 2004
    Location
    Copenhagen, Denmark
    Posts
    6,157
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    The most important thing about optimisation, is to not spend a lot of time optimising the wrong thing. Use a profiler before you touch any code.
    xdebug + wincachegrind are excellent tools for the job.

  4. #4
    SitePoint Wizard HarryR's Avatar
    Join Date
    Dec 2004
    Location
    London, UK
    Posts
    1,376
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Very good point about xdebug and cachegrind

    I was using it recently on a project to get a nice in-depth view of the average time the application is spending in each section of code spread out over a 24 hour period.

  5. #5
    SitePoint Addict chestertondevelopment's Avatar
    Join Date
    Dec 2005
    Location
    Essex, UK
    Posts
    241
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    The thing that will slow the script down the most is database queries, log slow queries and examine why they're running slow. A simple 10 minute change of a query will often result in a speed gain much greater than spending half a day changing going through code and changing to echo, pre-incrementing variables etc.

    It basically comes down to what kyber said, profile your pages and find out your bottlenecks before launching into changes that will have little effect, basically look for the best return on investment.

  6. #6
    SitePoint Zealot
    Join Date
    Mar 2007
    Posts
    196
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Which is better xdebug or cachegrind?
    Kayzio - We don't hesitate, we accelerate.

  7. #7
    SitePoint Addict chestertondevelopment's Avatar
    Join Date
    Dec 2005
    Location
    Essex, UK
    Posts
    241
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    xdebug is a PHP extension that profiles your application, it produces a file with the execution details. Cachegrind is a program which reads that output and shows it in a human readable format.

  8. #8
    SitePoint Zealot
    Join Date
    Mar 2007
    Posts
    196
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    thanks for the info stardustwd
    Kayzio - We don't hesitate, we accelerate.


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
  •