扩大PHP执行时间限制
我有一个关于 PHP 执行时间限制的问题。我需要运行一个脚本几个小时来发送 HTTP 请求。这些请求必须间隔一定的时间,因此整个过程应该需要几个小时。有人有使用下面的行为 PHP 设置这种时间限制的经验吗?例如:
ini_set('max_execution_time', 28800); // 8 hours
我知道这是一个奇怪的问题,但请告诉我这是否有效。蒂亚!
更新:我打算从浏览器中尝试。我不熟悉从命令行运行 PHP 脚本..我应该研究一下。我确实找到了一种获取此信息的替代方法,可以从 HTTP 请求中检索该信息;事实证明,我们有一个数据库,其中一些信息已经在本地长期积累。
I have a question about PHP's execution time limit. I need to run a script for many hours sending HTTP requests. These requests have to be apart a certain time, so that's why the whole thing is supposed to take hours. Does someone have experience setting this kind of time limit for PHP using the line below? For example:
ini_set('max_execution_time', 28800); // 8 hours
Strange question, I know, but let me know if this would work or not. TIA!
Update: I was going to try it from the browser. I'm not familiar with running PHP scripts from the command line.. I should look into this. I did found an alternate way to get this information that could be retrieved from the HTTP request; It turns out we have a database with some of the information already locally accumulated over a long period of time.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您是从浏览器还是从 CLI 运行它?如果从 CLI(正如您应该使用此类脚本一样),则没有执行时间限制(即
max_execution_time
硬编码为 0)Are you running this from browser or from CLI? If from CLI (as you should with such script), there is no exection time limit (i.e.
max_execution_time
is hardcoded to 0)一些(共享)主机不允许这样做
,我建议您维护上次尝试时间的日志(unix 时间戳),并使用 cron 执行一个脚本来检查是否有时间发出下一个 HTTP 请求,以及如果是,则将文件中的时间戳更新为当前时间戳。
希望有帮助
some (shared)hosts do not allow this
what i will suggest you is maintain a log of when was your last attempt (unix time stamp), and use cron to execute a script which checks if its time to make the next HTTP request, and if yes then update the timestamp in the file to current time stamp.
Hope that helps