Can you tell a php server to abort the execution o

2019-07-21 13:06发布

My web page uses an ajax call to return data from a very long php script, so if I exit the page early and reload the page, that php script is still being carried out, which will cause me problems.

Is there a way I could tell the server to abort the execution of the previous ajax request, if there is one that's still running?

thanks

标签: php abort
3条回答
时光不老,我们不散
2楼-- · 2019-07-21 13:37

Maybe try use set_time_limit() function for this script.

Or create some few php scripts and randomly generates a url for it.

查看更多
Anthone
3楼-- · 2019-07-21 13:45

did you try setting the XMLHttpRequest object to null when the page reloads?

查看更多
我想做一个坏孩纸
4楼-- · 2019-07-21 14:00

Not directly. You will need to set up a scheme where the work is offloaded to an external (to the web server) process, and that process has a communication channel with the web server set up that enables it to check if it should drop what it's doing every so often (e.g. a simple but not ideal scheme would be checking for the last-modified time of a "lock file"; if it's more than X seconds in the past, abort the task).

Your web page would then make a call to a script that would then "keep alive" the background task appropriately (e.g. by touching the lock file of the previous example).

This way, when the task is initiated through an AJAX request, the client begins making "keep-alive" requests to the server and the server forwards the "keep-alive" message to the external process. If the user reloads the page the "keep-alive" requests stop and the worker process will abort when the keep-alive threshold elapses. If all goes well and the work completes, your server would detect this through the communication channel it has with the worker process and report this back to the client on their next keep-alive "ping".

查看更多
登录 后发表回答