开发者

CakePHP Concurrent AJAX Requests Blocking

I am working with CakePHP on an app which has to run a time-consuming task via a single AJAX call, with secondary periodical AJAX calls checking on the progress of the task.

The Problem

While the time-consuming task (which takes >30 seconds) is running via it's AJAX request to CakePHP, the secondary progress AJAX request seems unable to be "blocking".

To clarify, the secondary progress AJAX request does not return any error, it simply does not return any response until the original time-consuming request finishes.

Once this original AJAX request finishes, the secondary progress AJAX request returns as expected.

It seems that execution of the progress request is being queued until the first AJAX call finishes, as the progress returned is 100%.

What I've Tried

I have tried multiple suggested solutions, including:

  • Changing the session handler to 'cake' in core.php - no fix
  • Setting the config 开发者_JAVA技巧security level to 'medium' in core.php - no fix
  • Disabling user agent checks in core.php - no fix
  • Testing multiple concurrent AJAX calls to a plain PHP script on the same server - works as expected

Any Ideas?

So it seems as though the issue is caused by CakePHP - has anyone experienced this in their own CakePHP app?

Thanks!


Session handling is set to file in php

from php.ini

[Session]
; Handler used to store/retrieve data.
; http://php.net/session.save-handler
session.save_handler = files

This prevent php from running more than one instance of session per user.

To prevent this run this in your php code:

session_write_close();

Just know session is now closed, so writing to session is no longer an option.


For some clarification, are you using the built-in AJAX helper (on prototype) or some external library like jQuery?

Usually, the javascript library of choice has an {async: true} available to force concurrency. See this example:

$.ajax({
    type: 'GET',
    url: '/fetch.php',
    async: true,
    success: function(data, status) {
        $('#status').html(status);
    }
});

For the built-in CakePHP AJAX helper, this option should do the trick: $options['type']. More info here. Do note that the AJAX helper is deprecated as of version 1.3 and the jsHelper should be able to takeover, see the request() method here for instance (also has an option called async).

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜