PHP每X分钟执行一次操作 [英] PHP perform action every X minutes

查看:145
本文介绍了PHP每X分钟执行一次操作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我制作了一个PHP脚本,该脚本从twitter获取推文并将其保存到文件中以供使用(作为JSON). 问题是我在执行脚本时只收到一次推文,但我希望每4-5分钟获得一次.

I've made a PHP script that gets tweets from twitter and saves them to a file for use (as JSON). Problem is that I only get the tweets once when I execute the script, but I want to get it about every 4-5 minutes.

我调查了sleep,但这只是延迟了浏览器并执行了一次操作. 我想每4分钟执行一次[strong] ,而不仅仅是延迟执行一次.

I've looked into sleep but that just delays the browser and executes the action once. I want to be executed every 4 minutes, not just once after a delay.

我也研究了cron,但是要在其上运行应用程序的服务器不允许我使用cron.

I looked into cron aswell but the server that I'm going to run my application on does not allow me to use cron.

TL; DR:有人知道一种在首次执行后每隔X分钟执行一次php脚本的好方法吗?

TL;DR: Anybody know a good way to execute a php script every X minutes after the first execution?

推荐答案

最好的选择是安排一个任务,每x分钟调用一次PHP页面,而不是尝试保持线程打开.看一看 CRON JOB .

The best bet for this would be to schedule a task to call your PHP page every x mins rather than trying to keep a thread open. Take a look at a CRON JOB.

如果您可以公开访问该页面,则无需从服务器执行计划任务.

The scheduled task doesn't need to be executed from the server if you make the page publically accessible.

这篇关于PHP每X分钟执行一次操作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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