Trung
Trung

Reputation: 650

Multiple Ajax request for PHP framework

I meet a trouble, that is I can't request 2 ajax at the same time with framework (Symfony)

Here is my code:

JQuery:

function doAjax1()
{
    $.ajax({
       url:  "server1.php",
       type: "POST",
       data: {
           id: 1,
       },
       success: function(){

       },
    });
}

function doAjax()
{
    $.ajax({
       url:  "server.php",
       type: "POST",
       data: {
           id: 1,
       },
       success: function(){

       },
    });
}

PHP Server:

sleep(10);
echo "Done 10s";

PHP Server1:

sleep(1);
echo "Done 1s";

First, I call doAjax() and second, doAjax1().

Without any framework, doAjax1() take about 1s, and doAjax() take about 10s, exactly what I want.

But with symfony 1.4 framework, doAjax1() take about 11s, and doAjax() take about 10s, it's seem doAjax() completed, doAjax1() call later.

Is there any safe solution for me?

Thank you.

Upvotes: 1

Views: 1225

Answers (3)

AlterPHP
AlterPHP

Reputation: 12727

Following examples are given for Symfony2 but the problem is the same, and the solution too.

This can be related to the session lock that Symfony operates on controller action. It it well described here :

The trick is : if you don't need to write in session during your action, free session lock as early as possible !

Here is 2 related questions :

Upvotes: 3

NHG
NHG

Reputation: 5877

I suppose that cause is your server configuration. It's looks like your PHP cannot execute more than 1 request in the same time. My suggestion is configure PHP workers.

Upvotes: -1

TheCodeDestroyer
TheCodeDestroyer

Reputation: 762

I would suggest you to use jQuery.when() to control ajax calls one after another, but don't think it will solve your performance issue with simphony, just a recommendation.

Upvotes: 1

Related Questions