简体   繁体   中英

PHP, Ajax, and the lifespan of the request

I was wondering about the lifespan of a PHP script when called via Ajax. Assume that there is a long-running (ie 30 seconds) PHP script on a server and that page is loaded via Ajax. Before the script completes, the user closes the browser. Does the script continue running to completion, is it terminated, or is this a function of the server itself (I'm running Apache fwiw). Thanks for any help.

This may be of interest: ignore_user_abort()

ignore_user_abort — Set whether a client disconnect should abort script execution

However note

PHP will not detect that the user has aborted the connection until an attempt is made to send information to the client.

The script will continue running. Closing the browser on the client does not notify the server to stop processing the request.

If you have a large time consuming script, then I would suggest splitting it up into chunks. Much better that way

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM