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.