Results 1 to 3 of 3

Thread: Does the number of php elements on a page affect performance?

  1. #1
    Join Date
    Mar 2005
    Location
    Western Australia
    Posts
    148
    Thanks
    24
    Thanked 4 Times in 4 Posts

    Default Does the number of php elements on a page affect performance?

    Hi, can I ask as per the title does the number of php elements in a page affect the performance of the pages load time and the servers CPU usage?

    I have a template I am building for a joomla site that will only load sections of the page to be viewed if there is content to be viewed in that section, at the same time the width of the sections will change depending on some settings variables and if other sections have content or not... I hope that makes sense.

    Now the code for the entire page gets quite long when you add all the checks to see if something has content or not and also the calculations to work out what to and what not to show and what style class to set to some of the sections to determine width etc.

    What I want to know is if the code I have would cause any cpu load issues at all.

    I'd appreciate anyone giving advice for tidying it up, maybe giving me help to improve the code a little and ensure it loads with the least amount of CPU use as possible. My knowledge of php is low but I am learning, so I am sure that from what I have someone will be able to optimise it further and make it run faster.

    Oh and also the top part which looks at the number of modules in a row and where there is 3 I have set it to be 99/3 and not 100/3, anyone have an idea how I can add the 1% back on to the middle module so I can have 33% 34% and 33% if there are 3 modules in a row?

    Attached is the html/php and main css as txt files if you have time to review and make comments on them

    Cheers

    GW
    Last edited by gwmbox; 02-13-2011 at 08:31 AM.
    1st rule of web development - use Firefox and Firebug
    2nd rule - see the first rule
    --
    I like Smilies

  2. #2
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,164
    Thanks
    265
    Thanked 690 Times in 678 Posts

    Default

    PHP is processed on the server, so yes it will cause an increased server load. That doesn't mean it will be a problem, but of course extra things on the page will be more than fewer things on the page.

    To be maximally efficient, you should try to avoid excessive repetition, but the number of <?php .... ?> sections will make a VERY VERY small difference, if any.

    Your code looks standard to me (at least the way it is integrated with the HTML-- I didn't look at the details). It should be fine.

    The best way to set this up is to have the major PHP operations at the top then minimal PHP in the page if possible. This usually includes conditional statements, maybe some loops, and then echoing variables. And that's what you have.
    Additionally, doing it this way makes the page easier to maintain and update.

    What you're doing seems just fine to me. I don't see any problem with it.


    If you ever want to know exactly how efficient/inefficient something is, you can put it in a loop and time how long it takes. For example, compare echo 'Hello World!'; and print('Hello World!'); in a loop of 1000 iterations. Check the time() before the loop, then compare that to the new time() after the loop. Display the change in time. By multiplying the operations like that, you'll find the slight differences.
    For this example, you could include the template page many times (100? 1000?) in a loop and see what happens. (I'd recommend using an output buffer so you don't need to deal with all of that text.)
    Daniel - Freelance Web Design | <?php?> | <html>| español | Deutsch | italiano | português | català | un peu de français | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum

  3. #3
    Join Date
    Mar 2005
    Location
    Western Australia
    Posts
    148
    Thanks
    24
    Thanked 4 Times in 4 Posts

    Default

    Thanks Daniel for your help and advice.

    Cheers

    GW
    1st rule of web development - use Firefox and Firebug
    2nd rule - see the first rule
    --
    I like Smilies

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
  •