如何使用PHP获得无限的最大执行时间? [英] How can I get infinite maximum execution time with PHP?

查看:179
本文介绍了如何使用PHP获得无限的最大执行时间?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个包含2000页的网站,我想使用file_get_html()函数和正则表达式遍历每个页面以生成站点地图.

I have a site with 2000 pages and I want to iterate through each page to generate a sitemap, using the file_get_html() function and regular expressions.

显然,这不能在一个服务器端执行中完成,因为由于执行时间最长,它会用完时间.我想它需要执行较小的操作,将进度保存到数据库中,然后将下一个任务排队.有什么建议吗?

Obviously this can't be completed in one server-side execution as it will run out of time due to maximum execution time. I guess it needs to perform smaller actions, save the progress to the database and then queue the next task. Any suggestions?

推荐答案

在命令行中运行它时,将没有最大执行时间.

When you run it command line there will be no maximum execution time.

如果提供商允许操作,您也可以使用set_time_limit(0);.

You can also use set_time_limit(0); for this if your provider allows manipulation.

我无法确定您的IP地址是否会被禁止-因为这取决于您向其发送请求的服务器的安全性.

I can't tell if your ip-address will get banned - as this depends on the security of the server you send your requests to.

其他解决方案

您可以获取一个(或几个)页面,并在整个源代码中搜索新的URL.然后,您可以将它们放在数据库中排队.然后,在下一次运行时,您将处理队列.

You can fetch one (or a few) page(s), and search for new URLs throughout the source code. You can then queue these in a database. Then on the next run, you process the queue.

这篇关于如何使用PHP获得无限的最大执行时间?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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