Please whitelist cPanel in your adblocker so that you’re able to see our version release promotions, thanks!

The Community Forums

Interact with an entire community of cPanel & WHM users!

PHP very laggy on cpanel server, help!

Discussion in 'General Discussion' started by jeffb101, Aug 26, 2003.

  1. jeffb101

    jeffb101 Registered

    Aug 25, 2003
    Likes Received:
    Trophy Points:
    Ok, I have a Dell Dual Processor 2.0GHZ Xeon, 1GB ECC RAM, 2x73GB SCSI drives server that has been chugging along and running perfect for the past few months.

    A couple of days ago users started reporting to me that pages were 'hanging' and they would have to refresh multiple times and wait a while to get into the site. I did some investgating, watched my server loads, looked at logs etc and couldn't find any problems.

    I've pretty much figured out that for some reason about 60% of the time any page I have is hanging when it gets to a php script. At that point it will freeze and either no display, or take a very long time to display.

    Static pages, and webhost manager, cpanel scripts etc seem to be running at regular speed, as well as e-mail and FTP which makes this more confusing!

    I do not think my server is overloaded, because if you look below on my TOP my cpu's are hardly being used (its a dual cpu, but for some reason redhat 7.3 detects it as quad, rackshack said this was normal), and barely any swap memory is being used.

    But what you can also see is that httpd proccesses are hanging around for 1, 2 or 3 minutes. I'm assuming these are the processes where php has hung.

    Ive configured apache httpd.conf and added more servers, more max users and all that good stuff, nothing helped. Upgraded my kernel to latest redhat 7.3, nothing helped.

    Reduce the timeout times in sysctl.conf, and optimized my my.cnf (even tho it happens to all php pages, not just mysql driven sites)!

    Can anyone offer me some insite? This is really annoying some of my users and I can find no solution. It seems to do it more when the server is under load, but my server load hasn't even gone up when this problem came.

    One other thing, when I run netstat there are like 500 TIME_WAIT connections, and I'm sure that means something, but I'm not a super linux guru so I don't know what. can anyone help please or give me some more ideas on how to diagnose the problem. Im having another 1gb of ram added to the server just to be on the safe side, but since I dont think its a resource problem in the first place I doubt that will fix it!!

    9:29pm up 5:00, 1 user, load average: 0.46, 0.88, 0.75
    132 processes: 131 sleeping, 1 running, 0 zombie, 0 stopped
    CPU0 states: 4.0% user, 5.0% system, 0.0% nice, 90.0% idle
    CPU1 states: 0.1% user, 1.0% system, 0.0% nice, 98.0% idle
    CPU2 states: 0.1% user, 2.0% system, 0.0% nice, 97.0% idle
    CPU3 states: 2.0% user, 1.1% system, 0.0% nice, 95.1% idle
    Mem: 1030676K av, 938392K used, 92284K free, 0K shrd, 93936K buff
    Swap: 2048276K av, 3072K used, 2045204K free 687476K cached

    8 root 14 0 0 0 0 SW 4.4 0.0 5:08 kscand
    29930 nobody 12 0 8188 8188 3464 S 3.4 0.7 0:01 httpd
    30312 nobody 13 0 7344 7344 3324 S 1.9 0.7 0:00 httpd
    28087 mysql 12 0 15204 14M 2136 S 1.4 1.4 0:03 mysqld
    29944 nobody 10 0 7076 7076 3312 S 1.4 0.6 0:01 httpd
    29933 nobody 11 0 7088 7088 3312 S 0.9 0.6 0:01 httpd
    29938 nobody 10 0 6972 6972 3328 S 0.9 0.6 0:01 httpd
    29950 nobody 11 0 7028 7028 3312 S 0.9 0.6 0:00 httpd
    30284 nobody 10 0 7028 7028 3328 S 0.9 0.6 0:00 httpd
    31079 root 13 0 1004 1004 760 R 0.9 0.0 0:00 top
    2312 named 10 0 4268 4268 908 S 0.4 0.4 0:07 named
    29954 nobody 10 0 7092 7092 3308 S 0.4 0.6 0:01 httpd
    29956 nobody 10 0 8900 8900 3444 S 0.4 0.8 0:01 httpd
    1 root 4 0 112 88 56 S 0.0 0.0 0:04 init Support Ticket Number:
    #1 jeffb101, Aug 26, 2003
    Last edited: Aug 26, 2003
  2. mickeymouse

    mickeymouse Well-Known Member

    Sep 16, 2003
    Likes Received:
    Trophy Points:
    Dear jeffb101,

    Please use the PHP stopwatch below to time the page\'s execution. Create a new file in the same directory as the slow webpage named timer.php and copy/paste the following into it:

    class BC_Timer{
    var $stime;
    var $etime;

    function get_microtime(){
    $tmp=split(\" \",microtime());
    $rt=$tmp[0] $tmp[1];
    return $rt;

    function start_time(){
    $this->stime = $this->get_microtime();

    function end_time(){
    $this->etime = $this->get_microtime();

    function elapsed_time(){
    return ($this->etime - $this->stime);
    After you do that and save the timer.php file, edit the file of the webpage that you think is slow, and insert the following PHP code:

    # start at the top of the file
    # with a PHP open tag
    $timer = new BC_Timer;

    # All your pre-existing PHP code goes here

    # then at the end of the file, insert:
    echo number_format($timer->elapsed_time(), 3) . \" seconds\";
    Save the changes and reload that webpage. Even very complicated PHP pages should execute in less than 1/10th of a second.

    If your script is taking longer, move the $timer->end_time(); line closer to the beginning of the script (after the call to start timer), save changes, and reload/refresh the page, check the time it took to execute. Keep moving the call to stop timer lower and lower and rechecking until you get a dramatic jump in elapsed time. That will show you where you need to improve your php coding. If your time dramatically slows down after a MySQL query, you should make sure that all JOINS are done correctly (that left joins are not done backwards with tables in the wrong order), that every column mentioned in the WHERE or ORDER BY clause of any SELECT query has a table index on that column, and that you have no VARCHAR type columns in any table. You can make table indexes on columns and change column types using your Control Panel. If your tables and queries are not optimized this way, then your queries will be hundreds of times slower than they would otherwise be.

    Regards, Support Ticket Number:
  3. bpamiri

    bpamiri Registered

    May 5, 2004
    Likes Received:
    Trophy Points:
    Any Resolution on this

    Was there any resolution on this. I have a brand new server that I have setup and am experiencing similar behaviour with php scripts being very slow.
  4. apodigm

    apodigm Well-Known Member

    May 12, 2003
    Likes Received:
    Trophy Points:
    I had (am having) a similar issue. However, the PHP stopwatch showed that the page was still rendering in less than a quarter second. So then I started thinking that it had something to do with Apache serving the rendered page to the client.

    I discovered that it was slow only for some websites and not the others. (which somewhat ruled out an apache-wide problem)

    I tested the same website on Netscape and IE. And for grins, I ran it through Mozilla (Firefox). Whoah! page loaded super fast in Firefox! I did some research and found that the problem has to do with the rendering engine in the client browser. IE, for example, will sometimes not render a <table> tag until it gets to the associated </table> tag. Since the slow website in question was closed by a table (with many nested tables) and had a lot of content from <body><table> to </table></body> that was causing the delay.

    You might see if this is similar for your problem website. You can break up the website with header table, content table, footer table, which can help a little too.

    Keep us posted on your testing and resolution since this is a very important PHP topic!
  5. jackal

    jackal Well-Known Member PartnerNOC

    Feb 23, 2002
    Likes Received:
    Trophy Points:
    Very Interesting!!

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice