最好的方式来管理长时间运行的PHP脚本? [英] Best way to manage long-running php script?

查看:115
本文介绍了最好的方式来管理长时间运行的PHP脚本?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个PHP脚本需要很长时间(5-30分钟)才能完成。为了防万一,脚本使用curl从另一个服务器中抓取数据。这是这么长时间的原因;它必须等待每个页面加载之前处理它并移动到下一个。

I have a PHP script that takes a long time (5-30 minutes) to complete. Just in case it matters, the script is using curl to scrape data from another server. This is the reason it's taking so long; it has to wait for each page to load before processing it and moving to the next.

我想要能够启动脚本,让它,直到它完成,这将在数​​据库表中设置一个标志。

I want to be able to initiate the script and let it be until it's done, which will set a flag in a database table.

我需要知道的是如何能够在脚本完成运行之前结束http请求。

What I need to know is how to be able to end the http request before the script is finished running. Also, is a php script the best way to do this?

推荐答案

当然可以用PHP来完成,但是你不应该

Certainly it can be done with PHP, however you should NOT do this as a background task - the new process has to be dissocated from the process group where it is initiated.

由于人们对此常见问题仍然给出相同的错误答案,因此,我在这里写了一个更完整的答案:

Since people keep giving the same wrong answer to this FAQ, I've written a fuller answer here:

http://symcbean.blogspot.com/2010/02/php-and-long-running-processes.html

这篇关于最好的方式来管理长时间运行的PHP脚本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆