dtcpvz8162 2014-02-05 13:11
浏览 35
已采纳

PHP请求输出需要很长时间才能收到

I´m stuck for 3 days trying to figure it out what is the cause of this problem. Lets go to the details:

A jquery ajax call loads a php file named HELPER, wich when loaded includes another php file called F1 that creates html table trough mysqli queries. Ajax get the response and paste the string in a html DIV. The response is a html table. The web server is apache2.2.

Problem is, the code runs in less than 1 second, but the response takes about 50 seconds. The response is only 20 KB.

Some simple HTML table code.
<?php
if (!$res = $sql->query("A QUERY")) { die('custom error 46'); }

if (!$res->num_rows > 0) { die('custom error 47'); }

$myStr = '';
while ( $row = $res->fetch_object() ) {
    if ($row->summary == "1") { 
        $mysum = " class='qtfck-table-summary'"; 
        $myIsSum = "Sim"; 
    } else { 
        $mysum = ""; 
        $myIsSum = ""; 
    }
    if(intval($row->id_centrodecusto) > 0) { 
        $mycc = "<input type='checkbox' name='" . $row->id_task . "' value='" . $row->id_centrodecusto . "' CHECKED />"; 
    } else { 
        $mycc = "<input type='checkbox' name='" . $row->id_task . "' value='' />"; 
    }
    $myj = " style='padding-left:" . intval($row->depth) * 10 . "px'";
    $myStr =    "<tr%s><td>%s</td><td><center>%s</center></td><td><center>%s</center></td><td%s>%s</td><td><center>%s</center></td><td><center>%s</center></td></tr>";
    echo sprintf($myStr,$mysum,$row->wbs,$row->depth,$myIsSum,$myj,$row->name,$row->uniqueid,$mycc); 
}
?>
Html Table closure

The timmings:

PHP START: 0.92 sec PHP END: 0.98 sec JS RECEIVED DATA: 49.50 sec JS PROCESSED DATA: 49.56 sec

I did some digging and it looks like the apache/httpd process (shell via top command) is going nuts, taking 100% CPU load during the full 50 seconds of wait.

BUT here´s something funny. If I change the string generated by the sprintf function and, let´s say, set some random string, there´s no problem at all.

Some simple HTML table code.
<?php
if (!$res = $sql->query("A QUERY")) { die('custom error 46'); }

if (!$res->num_rows > 0) { die('custom error 47'); }

$myStr = '';
while ( $row = $res->fetch_object() ) {
    if ($row->summary == "1") { 
        $mysum = " class='qtfck-table-summary'"; 
        $myIsSum = "Sim"; 
    } else { 
        $mysum = ""; 
        $myIsSum = ""; 
    }
    if(intval($row->id_centrodecusto) > 0) { 
        $mycc = "<input type='checkbox' name='" . $row->id_task . "' value='" . $row->id_centrodecusto . "' CHECKED />"; 
    } else { 
        $mycc = "<input type='checkbox' name='" . $row->id_task . "' value='' />"; 
    }
    $myj = " style='padding-left:" . intval($row->depth) * 10 . "px'";
    echo "<TR><TD>eZ6OnMCZgygePZeUQHcqbOmHQDxhDF4KzfkgOd198xhPFV2rRezlIqBdJLY2TcNlO0PLUmK6CQI9PQMZgkLrcoeYIYhM0x9xK4yQXIFb5SLdq32</TD><TD>UTuQPG9WCbOswuJMdkkckMoAW49C71IN9qKdk8OAdRRV3ZuCYxM5GEZKrXXrwE7cWHKTcXTiO4KwGjh1ejENvduZvEVkwA3zoHbWkzEjtFa1GMaNzD2rqswEDSoQix2CLziBNiHD8zliSWu5rvU8wd6dodWBvubvog</TD></TR>";
}
?>
Html Table closure

The response to this request is 50 KB in size.

The timmings:

PHP START: 0.78 sec PHP END: 0.81 sec JS RECEIVED DATA: 1.13 sec JS PROCESSED DATA: 1.19 sec

What I have already tried:

  • Use ob_start() and ob_end_flush().
  • Set apache mpm prefork SendBufferSize to a higher value, but I believe it was a long shot, as the longer response (50KB) has no problem.
  • Use echo instead of sprintf.

Anyone has a clue?

Best regards.

  • 写回答

1条回答 默认 最新

  • douji2283 2014-02-05 20:43
    关注

    I don´t know why but the problem was caused by the "center" html tags. Somehow the presence of the center tags slowdown the response. I just removed them and created appropriate css classes using "text-align: center" and the problem was gone.

    I also did try avoiding PHP to echo the HTML. Even then the tags causes problems again.

    Here´s the fix. I just don´t have an explanation for it.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥20 ML307A在使用AT命令连接EMQX平台的MQTT时被拒绝
  • ¥20 腾讯企业邮箱邮件可以恢复么
  • ¥15 有人知道怎么将自己的迁移策略布到edgecloudsim上使用吗?
  • ¥15 错误 LNK2001 无法解析的外部符号
  • ¥50 安装pyaudiokits失败
  • ¥15 计组这些题应该咋做呀
  • ¥60 更换迈创SOL6M4AE卡的时候,驱动要重新装才能使用,怎么解决?
  • ¥15 让node服务器有自动加载文件的功能
  • ¥15 jmeter脚本回放有的是对的有的是错的
  • ¥15 r语言蛋白组学相关问题