2014-05-22 22:22
浏览 61


I have a PHP application that does lengthy processing operations on databases. Those operations are processed using AJAX calls. When an AJAX call is triggered, the UI becomes blocked using the JQuery BlockUI Plugin ( In the message appearing, I included a button to cancel the request/processing if it is taking too long. I want the following behaviour:

When the "Cancel" button is clicked, all active AJAX calls must be aborted. Then, since the PHP script called is still running on the server side, I will trigger another AJAX call to set a PHP session variable to false. In the PHP script, I am constantly checking for the value of this variable so that if it is false, then I exit() the current script.

Could anyone please give me insight on how I can possibly trigger the aborting of all AJAX calls on pressing a "Cancel" button? In addition, is there a way in a PHP script to launch a separate thread that constantly checks for a session variable's value and accordingly exits all running PHP scripts/functions or at least the current one?

Thanks in advance, Jeremie

图片转代码服务由CSDN问答提供 功能建议

我有一个PHP应用程序,可以对数据库进行冗长的处理操作。 使用AJAX调用处理这些操作。 触发AJAX调用时,使用JQuery BlockUI插件阻止UI( /块/ )。 在出现的消息中,如果时间过长,我会在按钮中取消请求/处理。 我想要以下行为:

单击“取消”按钮时,必须中止所有活动的AJAX调用。 然后,由于调用的PHP脚本仍然在服务器端运行,我将触发另一个AJAX调用以将PHP会话变量设置为false。 在PHP脚本中,我不断检查这个变量的值,如果它是false,那么我退出()当前脚本。

任何人都可以告诉我如何知道如何 我可以在按下“取消”按钮时触发所有AJAX调用的中止? 另外,PHP脚本中是否有一种方法可以启动一个单独的线程来不断检查会话变量的值,从而退出所有正在运行的PHP脚本/函数,或者至少退出当前的那个?

提前致谢, Jeremie

  • 写回答
  • 好问题 提建议
  • 关注问题
  • 收藏
  • 邀请回答

1条回答 默认 最新

  • doucu9677 2014-05-22 22:33

    You can cancel an ajax request with .abort(). As for terminating PHP when a request is cancelled, you could use ignore_user_abort.

    You could make use of PHP workers to avoid letting users wait until PHP is done, google php workers. You'd find things like IronMQ and others, should be enough to get you going.

    解决 无用
    打赏 举报

相关推荐 更多相似问题