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

本文是小编为大家收集整理的关于PHP每隔X分钟执行一次行动的处理/解决方法,可以参考本文帮助大家快速定位并解决问题,中文翻译不准确的可切换到English标签页查看源文。

问题描述

我已经制作了一个php脚本,从Twitter中获取推文,并将它们保存到文件以供使用(如JSON). 问题是,当我执行脚本时,我只会得到推文,但我想每4-5分钟获得大约一4-5分钟.

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

我看着Cron Anwell,但是我打算运行我的应用程序的服务器不允许我使用Cron.

tl;博士:任何人都知道第一次执行后每x分钟执行PHP脚本的好方法?

推荐答案

最好的选择是为每一个x mins调用您的PHP页面而不是尝试打开一个任务.看看一个.

如果您将页面公开访问,则不需要从服务器执行预定任务.

其他推荐答案

您可以设置Web监视服务(有些是自由的,如pingdom),以使HTTP请求每x分钟请求您的页面,这应该执行技巧.

其他推荐答案

提供的提供者,但除了运行Cron作业的任何东西.调查它们,他们可以每x分钟称为您的PHP脚本.

本文地址:https://www.itbaoku.cn/post/1937808.html

问题描述

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.

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.

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: Anybody know a good way to execute a php script every X minutes after the first execution?

推荐答案

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.

其他推荐答案

You could set up a web monitoring service (some are free, like Pingdom) to make a HTTP request your page every X minutes, that should do the trick.

其他推荐答案

There are providers that offer nothing but running cron jobs for you. Look into them, they could just call your php script every x minutes.