简体   繁体   中英

How to stop Curl script

I've searched a lot but can not find a solution. I have this Curl script that downloads a file. The problem is that when the user cancels the loading of the script in the browser he continues downloading the file. I would like to know how to do it when the user reloads the page of the script or cancels the curl suspending the download of the file.

You will need to rewrite your code using the concept of "process queues" so that the work of downloading your file is being performed by a worker process that can be controlled independently of your main web server.

There are ways to write this yourself in PHP, but it would be better to look into existing solutions such as Gearman or PHP Resque to accomplish this.

Process queuing may seem intimidating at first, but it is really the only way to kick off large processes (image manipulation, large file downloads, etc) and be able to monitor their progress and terminate them independently.

You could do similar things by forking shell commands on your web server and potentially saving the PID and killing them later if desired, but that ends up being a nightmare to maintain compared to the above.

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