I'm having a bit of a response time issue with my PHP/MySQL site. When you access pages with DB connections, the response time is really slow. I've run DB queries in SQLyog and the response time there is great.

Currently running the following:
Windows 2003 Server SP2
Apache 2.0.55
PHP 5.2.3
MySQL 5.0.45
HP Proliant ML 370 G4
Dual Xeon 3.4GHz
4GB Ram

I use the server to store some drive images too, but there's really nothing else running on it but the site. Accessing the site from the server itself is slow as well.

I have the exact same setup on my laptop as a development environment, and it runs considerably faster when accessed over the network. Just to test it out, I set it up on a Linux box(Ubuntu 7.10, Single P4 2.66GHz, 512MB Ram on an IBM desktop PC) and the pages load in about 1/4th the time.

Any ideas on what would slow it down under Windows, besides Windows?

    jmclea,

    There are many reasons why the response time may be slow.

    Please check here for code that can be used to measure PHP Script Execution time. If this is a production system, just echo it into HTML Comments:

    <!-- put this at the top of the page --> 
    <?php 
       $mtime = microtime(); 
       $mtime = explode(" ",$mtime); 
       $mtime = $mtime[1] + $mtime[0]; 
       $starttime = $mtime; 
    ?> 
    <!-- put other code and html in here -->
    
    
    <!-- put this code at the bottom of the page -->
    <?php 
       $mtime = microtime(); 
       $mtime = explode(" ",$mtime); 
       $mtime = $mtime[1] + $mtime[0]; 
       $endtime = $mtime; 
       $totaltime = ($endtime - $starttime); 
       echo "<!-- Script Execution Time: ".$totaltime." seconds -->"; 
    ?>
    

    This is one method, another method would be to use the "Performance" moitor to watch CPU, TCP, Memory, etc while executing scripts known to take a long time.

    The idea is to find out exactly where the performance issue is. This does not seem to be hardware based (from what I can tell).

    All and all the best method is to closely monitor the performance of the system and look at what happens when specific requests come in, i.e. HTML Only, PHP Script (small), PHP Script (Large), etc.

      Thanks for the reply. I forgot to mention that in the original post. I came across that code last week and set it up to log to a file so I could see page performance over a period of time. I just went to the page and it takes about 5-7 seconds to display and the log reports that the page is generated in 0.0123 seconds. The first thing the page does is set the start time and the last thing is write the result to the log file.

      I've created a basic html file and it displays immediately. The switch it is in was showing some runt packets on the port, so I install a new NIC on the server and that didn't help either. I've looked at performance monitor while using the site, and it barely moves. All monitors are well below their problem thresholds.

      The page I'm using as an example is 927 lines long, but I have the same problem on another page that is on 97 lines long.

      I'm leaning towards 2003 as the culprit, since on XP the response time is much better using the same versions of Apache, MySQL & PHP.

        Is PHP being run as an Apache module or in CGI mode? (CGI mode will tend to be slower, as a new PHP process has to be launched for each request, I believe.)

          I've tried both with no noticeable difference.

            I've tried both with no noticeable difference.

            The difference will only appear under stress testing, so it may not be the source of the problem.

              I get the slow response all the time, even when there is no activity on the server.

              I found another interesting bit. The same page that takes 5-7 seconds to load in IE only takes about 1-2 seconds in Firefox. This is only from the Windows 2003 server though. When I access the same pages hosted on a Linux box, the pages load almost immediately in both browsers.

                Does the page output use a lot of tables, particularly nested tables? IE is notoriously slow at rendering nested tables, as it will not output anything within those tables until it receives all the nested content (possibly including images) and can calculate the sizes of the relevant table cells.

                If this is the case, it's yet another reason to avoid using tables for page layout. (For other reasons, see http://www.hotdesign.com/seybold/.)

                If that's not the issue, well at least that link might be useful for anyone who is still using tables for page layout. 🙂

                  One of the pages in questions does have 3 tables, but they are not nested. Upon looking at the code for that page, I noticed something that I had forgotten - the </TABLE> at the end of the last table. After I added that, the page began loading much faster in IE.

                  One thing I am still seeing is after the page displays on the screen, the IE "progress bar" on the status bar still goes for another 2-4 seconds.

                  Thanks for the link, I need to set aside some time to read through it all. I do need to do a redesign on the site anyway and that would be a good time to take out the tables and cleanup the ever expanding code.

                    Another good reason to run various pages of your site through a good validator to ensure that your HTML doesn't resemble alphabet soup (likewise for a good CSS validator).

                      4 days later

                      Thanks for all of your help with this. I've been able to eliminate most of slowness and I am in the process of redesigning the pages with less, or no, use of tables and more CSS.

                        Write a Reply...