cron 作业的保持活动解决方案
我有一个托管的网络解决方案和一个更新网站信息后端的脚本。
我的虚拟主机允许 cron,并且我制作了一个每小时 wget 的脚本。
该脚本检查数据库表中的帖子以更新最旧的更新帖子并更新它。在脚本的最后,我使用 javascript 刷新再次执行相同的过程,这次使用第二个最旧的更新帖子,依此类推,直到所有帖子都运行完毕。如果我在浏览器中打开脚本,它可以正常工作,但是当我的主机设置 cron 时,脚本在 javascrpt 刷新后不会继续。
如何使用另一个刷新解决方案来解决这个问题,该解决方案将一直有效,直到 my 语句仅通过让 cron 启动脚本来停止它?
(我从所有帖子都在一个页面加载中更新的解决方案更改为这个解决方案,但由于它开始超时,所以我选择了这个)
script.php
$limit=3600;
//Select the oldest updated post
if($last_update<$update_to_limit){ //check if the post was updated during this run
// Script that update the post and below the java refresh that repeats the script.
?>
<script type="text/javascript">
<!--
window.location.href = "http://www.site.se/script.php"
//-->
</script>
<?php
}else{
echo 'OK : All posts updated within the last : '.$limit.' s';
}
I have a hosted websolution and a script that update information backend for the site.
My webhost allows cron and I have made a script that wget's to every hour.
The script checks the db-table with posts to update for the oldest updated post and update that. In the end of the script I use javascript refresh to do the same procedure again this time with the second oldest updated post and so on until all posts are run through. If I open the script in my browser it works fine but when my host sets up the cron the script does not continue after the javascrpt refresh.
How can I solve this with another refresh solution that will work until the my statement stops it just by letting cron start the script?
(I changed to this solution from one where all posts were updated in one pageload but since it started to time out I went with this)
script.php
$limit=3600;
//Select the oldest updated post
if($last_update<$update_to_limit){ //check if the post was updated during this run
// Script that update the post and below the java refresh that repeats the script.
?>
<script type="text/javascript">
<!--
window.location.href = "http://www.site.se/script.php"
//-->
</script>
<?php
}else{
echo 'OK : All posts updated within the last : '.$limit.' s';
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
Wget 不会运行 Javascript,如果你从浏览器打开代码,它当然会运行它,这就是差异的原因。
我真的不建议您尝试使用的方法。如果您确实想要,您可以从 PHP 再次调用
wget
,使用cURL
或者我猜甚至是header('Location..');
。但如果能一次性解决这个问题就更好了。如果你的代码超时,我会重新检查PHP代码的编写方式,并尝试找到更好的解决方案,这样就不会那么耗时。之后:数据库是否足够好,索引是否设置等。或者,如果您无法优化它(或者您不想),您可以使用 set_time_limit()。
(还有一件事:Java!=Javascript。如果你想缩短它,就写js而不是java)
Wget will not run Javascript, if you open your code from the browser, it will of course run it, that is the reason of the difference.
I don't really suggest the method you're trying to use. If you really want, you can call
wget
again from PHP, usecURL
or I guess evenheader('Location..');
. But it would be much nicer to solve this problem in one turn.If your code times out, I'd recheck the way that PHP code is written, and try to find a better solution, that is not so time-consuming. Afterwards: is the DB good enough, are the indexes set, etc. Or, if you cannot optimize it (or you do not want to), you can use set_time_limit().
(One more thing: Java!=Javascript. If you want to shorten it, write js instead of java)