Why is the "waiting" duration on my Ajax call? (Chrome Network Panel)

I have several ajax calls on a page that is requesting some json content. In all these calls, I get a significant waiting time for a response. For each of these calls, the session has a “waiting” period of several seconds, as shown in the Chrome Network panel below. I added a photo:

Waiting On the Ajax Call - screenshot 1

I'm not quite sure what causes this, since I did some benchmarking in php code that requests the database, and accordingly calling the request and processing json to send back works in 0.001 seconds or so.

, ? , ? , ? . , , - .

( ajax, , get_usergames_simple call: All the requests

, ajax:

self.getGamesContent = function()
{
  var userID = "<?php echo $userID; ?>";

  var post_data = {
    userID: userID
  };

  $.post("https://mydomain.com/games/get_usergames_simple/", post_data, function(result)
  {
    var json = $.parseJSON(result);

    var mappedGames = $.map(json.games, function(item) {
      return new GameItem(item)
    });
    self.gameitems(mappedGames);
  });
};

PHP- , :

$userID = $this->input->post('userID');
$this->benchmark->mark('code_start');

$userGames = $this->cache->model('games', 'getGamesSimpleByUserID', array($userID), 120); // keep for 2 minutes

$returnString = "{";

$returnString .= '"user_id": "' . $userID . '",';

$gameCount = 0;

$returnString .= '"games": [';
foreach ($userGames as $ug)
{
  $returnString .= "{";
  $returnString .= '"user_id" : "' . $userID . '",';
  $returnString .= '"game_id" : "' . $ug->GameID . '",';
  $returnString .= '"game_name" : "' . $ug->GameName . '",';
  $returnString .= '"game_image" : "' . $ug->GameImage . '",';
  $returnString .= '"description" : "' . htmlspecialchars($ug->GameDescription) . '",';
  $returnString .= '"genre_id" : "' . $ug->GameGenreCatID . '",';
  $returnString .= '"genre_name" : "' . $ug->GameGenreName . '",';
  $returnString .= '"publisher_id" : "' . $ug->GamePublisherID . '",';
  $returnString .= '"publisher_name" : "' . $ug->GamePublisherName . '",';
  $returnString .= '"developer_id" : "' . $ug->GameDeveloperID . '",';
  $returnString .= '"developer_name" : "' . $ug->GameDeveloperName . '",';
  $returnString .= '"active_flag" : "' . $ug->GameIsActive . '",';
  $returnString .= '"create_date" : "' . $ug->GameCreateDate . '",';
  $returnString .= '"remove_date" : "' . $ug->GameRemoveDate . '",';
  $returnString .= '"last_update_date" : "' . $ug->GameLastUpdateDate . '",';
  $returnString .= '"user_syncing_game" : "' . $ug->UserSyncingGame . '"';
  $returnString .= "},";
  $gameCount++;
}

if ($gameCount > 0)
  $returnString = substr($returnString, 0, strlen($returnString) - 1);

$returnString .= "]}";


$this->benchmark->mark('code_end');

//echo $this->benchmark->elapsed_time('code_start', 'code_end');

echo $returnString;
+5

All Articles