简体   繁体   English

PHP Cron Job的替代品,可长期运行

[英]Alternatives to PHP Cron Job for Long Running Jobs

We have a website that lists links to blogs in realtime. 我们有一个网站,该网站会实时列出指向博客的链接。 The problem is that the pages are slow to load because they are reading data from the various source sites. 问题在于页面加载缓慢,因为它们正在从各个源站点读取数据。

I wrote a PHP script that creates an HTML version of each page. 我编写了一个PHP脚本,用于创建每个页面的HTML版本。 This runs once each hour. 每小时运行一次。 The problem is that the PHP script is timing out before it finishes all the pages. 问题在于PHP脚本在完成所有页面之前超时。 I know that I could increase the execute time allowed for PHP scripts, but this does not seem like the most efficient way to handle the issue. 我知道我可以增加PHP脚本允许的执行时间,但这似乎不是解决问题的最有效方法。

Is there another way to do this? 还有另一种方法吗? I just don't know what to begin looking for - PERL? 我只是不知道该开始寻找什么-PERL? JAVA? JAVA? Python? 蟒蛇? How do these scripts run on a server? 这些脚本如何在服务器上运行? What should I look for from my web host? 我应该从我的虚拟主机上寻找什么?

Python with urllib2 will probably do a good job. 带有urllib2的Python可能会做得很好。 Also, do I understand this right: you have a site that aggregates data from other sites, and it's all generated static HTML? 另外,我是否理解这一权利:您有一个站点,该站点聚集了其他站点的数据,并且全部生成了静态HTML? It sounds like you're kind of using HTML as a database, so maybe consider using a proper one. 听起来您好像在使用HTML作为数据库,所以也许考虑使用适当的数据库。

Given the fact that your original problem is one of network latency ("pages are slow to load") I see no reason to believe that PHP is the bottleneck here. 考虑到您原来的问题是网络延迟(“页面加载缓慢”)之一,因此我认为没有理由相信PHP是这里的瓶颈。 I doubt changing languages will affect your script run time. 我怀疑更改语言会影响您的脚本运行时间。

A different solution might be to use a database, and not bite off so much work at once. 另一种解决方案可能是使用数据库,而不是一次完成很多工作。 Make a table listing the sites you pull, and store when they were last pulled. 制作一张表格,列出您拉出的站点,并存储上次拉出的时间。 Then have the cron pull out 1 or 2 that haven't been pulled in a while. 然后将cron拔出一段时间没有拉出的1或2。 Have it run often, then you'll always have fresh data, but the script will have an easier time working as its not trying to do so much at once. 如果经常运行它,那么您将始终拥有新鲜的数据,但是该脚本可以更轻松地工作,因为它不会立即尝试执行很多操作。 This concept will scale well. 这个概念将很好地扩展。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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