Forum Moderators: coopster
First I'll try and describe the architecture of some of my code, and then describe my problem to see if anybody out there can help. The code outlines are only included to show the technology mix and you'll see that you need not analyse it too much.
// .js (javascript file). Bind function
// actionOptAdd to a submit button using jQuery
//
$(".actionOptAdd").bind("click",
function()
{
.
.
.
.
$.getJSON('lib/addToProj.php',
{
.
.
.
.
}, function(data)
{
.
.
$.each(data, function(i,item)
{
//deal with data
}
// write to the HTML some status
message
}
}
// Here's the HTML with PHP code where the above actionOptAdd is
associated with the clicking of a button:
<span id="Add_<?php print $i; ?>" class="actionOptAdd"> <input
type="button" name="btnOk_AddToProject_<?php print $i; ?>"
class="button-click-grey" value="Add to Project" /><span>
//And here's the outline of PHP code for addToProj.php................
<?php
include_once("configFiles.php");
$json_array = array(.....
// do some database transactions.
// code here is not important for the problem I am describing
echo json_encode($json_array);
// end------------------
And now I will describe the problem I am getting. I am finding that occasionally the addToProj code hangs. At the beginning of the session, you can click the button (actually different instances of the button on the page), to which the actionOptAdd function is bound, three or four times (for different data) and then you get the hanging and have to wait 5 minutes or so before you can proceed.
I use firephp to debug and the console diagnostics tell me that it is entering AddToProj (when users click the button). It hangs right at the beginning of AddToProj because I have inserted $firephp->log statements right at the beginning of the configFiles.php which don't get executed before it hangs. If the log statements are being inserted at the very earliest opportunity, there is apparently nothing that can hang - but, yes, it sits there for a few minutes before eventually continuing successfully
through to the end.
So my questions are: a) what are the likely reasons for it hanging? b) What debugging tools can I use to investigate further? (Perhaps I need to do more with FirePHP than plan log to console messages?) c) Is there a chance that one of the Zend tools or XCache, PHP Accelerator or APC will help?
which don't get executed before it hangs
So you are not even getting into the PHP script? tail your access logs so you can see the request coming in, then at that point at least you know the request isn't hanging at the browser. Once you see the request in the access log you know that the server is starting it's response. Log a message at the VERY beginning of the PHP script and then start analyzing the included files by logging an entry for each of those in turn.
require_once('../../FirePHPCore/FirePHP.class.php');
ob_start();
$firephp = FirePHP::getInstance(true);
In the console you see something like....
-GET [<domain>...] here>
... and the curly thing rotating at the end of the line indicating that its waiting. Eventually it does come back.
So, actually it is the GET that hangs. Can I remind you that usually a few GETs (on clicking on the button to which the function actionOptAdd is bound) work fine, and then suddenly a GET hangs.