1

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.

3
  • Where do you call doAjax() and doAjax1()? Commented Aug 14, 2013 at 6:54
  • Please provide your server configuration. Commented Aug 14, 2013 at 7:02
  • Notice: you should not use Symfony 1.4 - it is deprecated. Please use Symfony 2.3. Commented Aug 14, 2013 at 7:09

3 Answers 3

3

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 :

Sign up to request clarification or add additional context in comments.

2 Comments

Thank you. Your links are useful for me.
The first link helped me. Thx!
1

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.

Comments

-1

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.