This question already has an answer here:
这个问题在这里已有答案:
- PHP: running scheduled jobs (cron jobs) 13 answers
PHP:运行预定作业(cron jobs)13个答案
I have a PHP script that checks my database's code for validity. How can I have this run everyday at a certain time so then I can just have it run on autopilot.
我有一个PHP脚本,检查我的数据库的代码是否有效。我怎样才能在某个时间每天运行这个运行所以我可以让它在自动驾驶仪上运行。
8 个解决方案
#1
14
What you want is called a cron job and is already covered here:
你想要的是一个cron工作,这里已经涵盖了:
PHP: running scheduled jobs (cron jobs)
PHP:运行预定作业(cron作业)
#2
6
If you are using cPanel on your host, you can go to Advanced --> cron jobs. Then inside there you can set a cron job command like this:
如果您在主机上使用cPanel,则可以转到高级 - > cron作业。然后在那里你可以像这样设置一个cron job命令:
wget http://yoursite.com/yourfile.php
which http://yoursite.com/yourfile.php
should point to your desired function. You can also set repetition time interval over there.
其中http://yoursite.com/yourfile.php应该指向您想要的功能。您还可以在那里设置重复时间间隔。
This way yourfile.php
is called in specified intervals.
这样,在指定的时间间隔内调用yourfile.php。
#3
3
CronJobs feature are often disabled on most free or cheap Linux hosting. If you could use cron you could use that.
CronJobs功能通常在大多数免费或廉价的Linux主机上禁用。如果你可以使用cron,你可以使用它。
Alternatives:
- Use services like : http://www.setcronjob.com/ (many exist, just search on google) , to schedule your task for free(1x per hour).
- If you need a little bit more juice you should look into google app engine cron. In the cron you just do a simple asynchronous request to call your page.
使用以下服务:http://www.setcronjob.com/(许多存在,只需在谷歌搜索),免费安排您的任务(每小时1次)。
如果你需要更多的果汁,你应该看看谷歌应用程序引擎cron。在cron中,您只需执行一个简单的异步请求即可调用您的页面。
#4
1
There's a cli interpreter called php
. Run your script through that as a cron job.
有一个名为php的cli解释器。通过它作为cron作业运行您的脚本。
#6
0
May it will helps you.
愿它能帮到你。
You can schedule a task in Windows - control panel->administrative tools is where you find task scheduler.
您可以在Windows中安排任务 - 控制面板 - >管理工具,您可以在其中找到任务计划程序。
run a php automatically after every hour
每小时后自动运行一次php
Thanks
#7
-1
If you have your own server you can run a cronjob(unix/linux) or a scheduled task(windows).
如果您有自己的服务器,则可以运行cronjob(unix / linux)或计划任务(windows)。
If your app/site is hosted on a shared host that does not offer cronjobs you an use a sevice like http://www.onlinecronjobs.com/
如果您的应用/网站托管在不提供cronjobs的共享主机上,您可以使用http://www.onlinecronjobs.com/这样的服务。
I have not tested this one but If you google a bit(fee conjobs) you will find plenty of those. They will call a certain a url accoding to a fixed schedule. Most of those sevices have a fixed set of ip addeses so you can pevent the scipt from being called by anyone else.
我没有测试过这个,但如果你谷歌一点(费用合唱),你会发现很多这些。他们会根据固定的时间表拨打某个网址。大多数这些服务都有一组固定的ip addeses,因此你可以防止scipt被其他人调用。
#8
-1
You can easily use your database to save the last execution of the script.
您可以轻松使用数据库来保存脚本的上次执行。
Each execution of a certain page you run a script that does the following :
每次执行某个页面时,您都会运行执行以下操作的脚本:
-
Check if more than 8 hours (example)
检查是否超过8小时(例如)
-
Checks in the database if the script has already been executed
如果脚本已经执行,则检查数据库
If executed: does nothing.
如果执行:什么都不做。
If not executed: starts and updates the date last execution in database.
如果未执行:启动并更新数据库中上次执行的日期。
#1
14
What you want is called a cron job and is already covered here:
你想要的是一个cron工作,这里已经涵盖了:
PHP: running scheduled jobs (cron jobs)
PHP:运行预定作业(cron作业)
#2
6
If you are using cPanel on your host, you can go to Advanced --> cron jobs. Then inside there you can set a cron job command like this:
如果您在主机上使用cPanel,则可以转到高级 - > cron作业。然后在那里你可以像这样设置一个cron job命令:
wget http://yoursite.com/yourfile.php
which http://yoursite.com/yourfile.php
should point to your desired function. You can also set repetition time interval over there.
其中http://yoursite.com/yourfile.php应该指向您想要的功能。您还可以在那里设置重复时间间隔。
This way yourfile.php
is called in specified intervals.
这样,在指定的时间间隔内调用yourfile.php。
#3
3
CronJobs feature are often disabled on most free or cheap Linux hosting. If you could use cron you could use that.
CronJobs功能通常在大多数免费或廉价的Linux主机上禁用。如果你可以使用cron,你可以使用它。
Alternatives:
- Use services like : http://www.setcronjob.com/ (many exist, just search on google) , to schedule your task for free(1x per hour).
- If you need a little bit more juice you should look into google app engine cron. In the cron you just do a simple asynchronous request to call your page.
使用以下服务:http://www.setcronjob.com/(许多存在,只需在谷歌搜索),免费安排您的任务(每小时1次)。
如果你需要更多的果汁,你应该看看谷歌应用程序引擎cron。在cron中,您只需执行一个简单的异步请求即可调用您的页面。
#4
1
There's a cli interpreter called php
. Run your script through that as a cron job.
有一个名为php的cli解释器。通过它作为cron作业运行您的脚本。
#5
#6
0
May it will helps you.
愿它能帮到你。
You can schedule a task in Windows - control panel->administrative tools is where you find task scheduler.
您可以在Windows中安排任务 - 控制面板 - >管理工具,您可以在其中找到任务计划程序。
run a php automatically after every hour
每小时后自动运行一次php
Thanks
#7
-1
If you have your own server you can run a cronjob(unix/linux) or a scheduled task(windows).
如果您有自己的服务器,则可以运行cronjob(unix / linux)或计划任务(windows)。
If your app/site is hosted on a shared host that does not offer cronjobs you an use a sevice like http://www.onlinecronjobs.com/
如果您的应用/网站托管在不提供cronjobs的共享主机上,您可以使用http://www.onlinecronjobs.com/这样的服务。
I have not tested this one but If you google a bit(fee conjobs) you will find plenty of those. They will call a certain a url accoding to a fixed schedule. Most of those sevices have a fixed set of ip addeses so you can pevent the scipt from being called by anyone else.
我没有测试过这个,但如果你谷歌一点(费用合唱),你会发现很多这些。他们会根据固定的时间表拨打某个网址。大多数这些服务都有一组固定的ip addeses,因此你可以防止scipt被其他人调用。
#8
-1
You can easily use your database to save the last execution of the script.
您可以轻松使用数据库来保存脚本的上次执行。
Each execution of a certain page you run a script that does the following :
每次执行某个页面时,您都会运行执行以下操作的脚本:
-
Check if more than 8 hours (example)
检查是否超过8小时(例如)
-
Checks in the database if the script has already been executed
如果脚本已经执行,则检查数据库
If executed: does nothing.
如果执行:什么都不做。
If not executed: starts and updates the date last execution in database.
如果未执行:启动并更新数据库中上次执行的日期。