如何在没有cron,perl等的情况下每5-10分钟运行一次PHP脚本?

时间:2022-05-19 01:02:53

I want to run a script every 5 minutes on server. I have not any type of administrate privileges to do cron job etc.

我想在服务器上每5分钟运行一次脚本。我没有任何类型的管理权限来做cron job等。

I am not good php programmer so this question may look strange, but if you understand please tell me a solution.

我不是很好的php程序员,所以这个问题可能看起来很奇怪,但如果你理解,请告诉我一个解决方案。

9 个解决方案

#1


14  

I use webcron.org wich is an affordable online service. Advantage for me is that I then have an overview of all scheduled tasks, on all servers.

我使用webcron.org这是一个经济实惠的在线服务。对我而言,优势在于我可以在所有服务器上概览所有计划任务。

#2


15  

Sounds like your only solution would be "Poor Man's Cron".

听起来你唯一的解决方案就是“穷人的Cron”。

What you do is create a script that you place on top of every page that only runs every 5 minutes. It won't be guaranteed to run every 5 minutes though. As it requires someone to visit the pages with the "poor man's cron" and if no one visits for over 5 minutes then it won't run until someone does.

你所做的是创建一个脚本,放在每隔5分钟运行一次的每个页面上。但不保证每隔5分钟运行一次。因为它需要有人访问“穷人的cron”的页面,如果没有人访问超过5分钟,那么它将不会运行,直到有人这样做。

Some example code:

一些示例代码:

<?php
 // load the last run time from a file, database, etc
 if(time() >= $last_run + (60 * 5)) { // 60 * 5 is 5 minutes
     // do your task here
     // save the last run time to a file, database, etc
 }

#3


11  

Here's another 'hack'. Since you can't run cron on the machine where the script is, maybe you can run cron on another machine.

这是另一个'黑客'。由于你无法在脚本所在的机器上运行cron,也许你可以在另一台机器上运行cron。

If you can...setup a cron job to run every 5 minutes...The job can be a simple PHP script that calls your other PHP script. You can use cURL to 'call' your script (if that script is being served up by a Web Server)

如果你可以...设置一个cron作业每5分钟运行一次......作业可以是一个简单的PHP脚本,可以调用你的其他PHP脚本。您可以使用cURL“调用”您的脚本(如果该脚本由Web服务器提供)

#4


3  

See this and this.

看到这个和这个。


(Edited to include content from the links.)

(已编辑以包含链接中的内容。)

  • PHP Cron Daemon is driven by a database to schedule the execution of task (like cron). It can parse a crontab file and extract the job scheduling definitions into a MySQL database table. When it is time to run a scheduled job, it executes the job command in the crontab definition as PHP code as a separate process. The output of the job PHP code is also stored in a database table.
  • PHP Cron守护程序由数据库驱动,以安排任务的执行(如cron)。它可以解析crontab文件并将作业调度定义提取到MySQL数据库表中。当需要运行预定作业时,它会将crontab定义中的作业命令作为PHP代码作为单独的进程执行。作业PHP代码的输出也存储在数据库表中。

#5


2  

That is how I do it

这就是我的方式

if(date('i', time())%5==0) {
// run this code
}

#6


1  

Something like:

就像是:

ini_set('max_execution_time', 'sometime'); 
while(1){
    //do something
    sleep(sometime);
}

Although I don't recommend doing this. Time to move to a server that meets your needs.

虽然我不建议这样做。是时候搬到满足您需求的服务器了。

#7


1  

I'm sure this tools can help you with your request:

我确信这些工具可以帮助您满足您的要求:

SetCronJob - www.setcronjob.com

SetCronJob - www.setcronjob.com

Cronless - cronless.com

Cronless - cronless.com

EasyCron - www.easycron.com

EasyCron - www.easycron.com

Online Cron Jobs - www.onlinecronjobs.com

在线Cron Jobs - www.onlinecronjobs.com

Corntab - www.corntab.com

Corntab - www.corntab.com

getCron - www.getcron.com

getCron - www.getcron.com

However, it's not good idea to depend from another website.

但是,依赖其他网站并不是一个好主意。

Tanks to Google

坦克到谷歌

#8


1  

My solution if your server is Linux. Make bash script:

我的解决方案,如果你的服务器是Linux制作bash脚本:

#bin/bash
while [ true ]
do
     //do whatever you want, use curl, lynx to your page...
     sleep 5m
done

Run it and if your server would not reboot or script would not killed you will be fine.

运行它,如果您的服务器不会重新启动或脚本不会被杀死,你会没事的。

This one isn't good solution, but works.

这个不是好的解决方案,但有效。

#9


0  

I would recommend this service, I used it today, and it seems to work well.

我会推荐这项服务,今天我用它,它似乎运作良好。

Cron-Job

克龙 - 工作

and yes, it is Free!

是的,它是免费的!

#1


14  

I use webcron.org wich is an affordable online service. Advantage for me is that I then have an overview of all scheduled tasks, on all servers.

我使用webcron.org这是一个经济实惠的在线服务。对我而言,优势在于我可以在所有服务器上概览所有计划任务。

#2


15  

Sounds like your only solution would be "Poor Man's Cron".

听起来你唯一的解决方案就是“穷人的Cron”。

What you do is create a script that you place on top of every page that only runs every 5 minutes. It won't be guaranteed to run every 5 minutes though. As it requires someone to visit the pages with the "poor man's cron" and if no one visits for over 5 minutes then it won't run until someone does.

你所做的是创建一个脚本,放在每隔5分钟运行一次的每个页面上。但不保证每隔5分钟运行一次。因为它需要有人访问“穷人的cron”的页面,如果没有人访问超过5分钟,那么它将不会运行,直到有人这样做。

Some example code:

一些示例代码:

<?php
 // load the last run time from a file, database, etc
 if(time() >= $last_run + (60 * 5)) { // 60 * 5 is 5 minutes
     // do your task here
     // save the last run time to a file, database, etc
 }

#3


11  

Here's another 'hack'. Since you can't run cron on the machine where the script is, maybe you can run cron on another machine.

这是另一个'黑客'。由于你无法在脚本所在的机器上运行cron,也许你可以在另一台机器上运行cron。

If you can...setup a cron job to run every 5 minutes...The job can be a simple PHP script that calls your other PHP script. You can use cURL to 'call' your script (if that script is being served up by a Web Server)

如果你可以...设置一个cron作业每5分钟运行一次......作业可以是一个简单的PHP脚本,可以调用你的其他PHP脚本。您可以使用cURL“调用”您的脚本(如果该脚本由Web服务器提供)

#4


3  

See this and this.

看到这个和这个。


(Edited to include content from the links.)

(已编辑以包含链接中的内容。)

  • PHP Cron Daemon is driven by a database to schedule the execution of task (like cron). It can parse a crontab file and extract the job scheduling definitions into a MySQL database table. When it is time to run a scheduled job, it executes the job command in the crontab definition as PHP code as a separate process. The output of the job PHP code is also stored in a database table.
  • PHP Cron守护程序由数据库驱动,以安排任务的执行(如cron)。它可以解析crontab文件并将作业调度定义提取到MySQL数据库表中。当需要运行预定作业时,它会将crontab定义中的作业命令作为PHP代码作为单独的进程执行。作业PHP代码的输出也存储在数据库表中。

#5


2  

That is how I do it

这就是我的方式

if(date('i', time())%5==0) {
// run this code
}

#6


1  

Something like:

就像是:

ini_set('max_execution_time', 'sometime'); 
while(1){
    //do something
    sleep(sometime);
}

Although I don't recommend doing this. Time to move to a server that meets your needs.

虽然我不建议这样做。是时候搬到满足您需求的服务器了。

#7


1  

I'm sure this tools can help you with your request:

我确信这些工具可以帮助您满足您的要求:

SetCronJob - www.setcronjob.com

SetCronJob - www.setcronjob.com

Cronless - cronless.com

Cronless - cronless.com

EasyCron - www.easycron.com

EasyCron - www.easycron.com

Online Cron Jobs - www.onlinecronjobs.com

在线Cron Jobs - www.onlinecronjobs.com

Corntab - www.corntab.com

Corntab - www.corntab.com

getCron - www.getcron.com

getCron - www.getcron.com

However, it's not good idea to depend from another website.

但是,依赖其他网站并不是一个好主意。

Tanks to Google

坦克到谷歌

#8


1  

My solution if your server is Linux. Make bash script:

我的解决方案,如果你的服务器是Linux制作bash脚本:

#bin/bash
while [ true ]
do
     //do whatever you want, use curl, lynx to your page...
     sleep 5m
done

Run it and if your server would not reboot or script would not killed you will be fine.

运行它,如果您的服务器不会重新启动或脚本不会被杀死,你会没事的。

This one isn't good solution, but works.

这个不是好的解决方案,但有效。

#9


0  

I would recommend this service, I used it today, and it seems to work well.

我会推荐这项服务,今天我用它,它似乎运作良好。

Cron-Job

克龙 - 工作

and yes, it is Free!

是的,它是免费的!