Sirabbub 0 Newbie Poster

I've got a problem with a web application that runs slow when called by JQuery? Below I will be summarising the structure of the application, but just to say that it is hanging inconsistently and unpredictably as if the (dedicated) webserver runs out of memory or too many database connections or something. Here is the structure (and more details follow later)....

// .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
bound to 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>

PHP code outline for addToProj.php.......

<?php
include_once("configFiles.php");
$json_array = array(.....
 do some database transactions
echo json_encode($json_array); // the .each loop in the jQuery can then analyse the output

The PHP/HTML actually binds the addtoproj (via the jQuery) to 10 or more buttons on the page (in a PHP loop, so the same code is involved but the data varies). The user can click on each button in turn to save to the database (that's what addtoproj does), but sometimes (but far too often) the addtoproj hangs, right at the beginning of the function before having the chance to do anything, even if the previous addtoproj invocations have completed (I can see all this via firephp). Its not stuck in a loop, not busy saving anything to the database, not apparently doing anything except hanging at the very beginning of addtoproj, just after the lines necessary to enable firephp.

In the firephp console you see something like....

-GET http://www.<domain>/app/lib/addtoproj.php?<arguments here>

... and the rotating thing 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. Perhaps there are some key PHP variables I need to adjust in the PHPini file? I've already increased memory_limit a couple of times (currently set to -1 for no memory limit).

This is quite a long description (sorry) but I wanted to give as much detail as possible.

All help will be very much appreciated.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.