如何通过PHP脚本设置cron作业 [英] How can I set cron job through PHP script

查看:83
本文介绍了如何通过PHP脚本设置cron作业的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何通过PHP脚本设置cron作业。

How can I set cron job through PHP script.

推荐答案

这将添加一个脚本, 30am。

This will add a script that runs every day at 9:30am.

exec('echo -e "`crontab -l`\n30 9 * * * /path/to/script" | crontab -');

如果从Web服务器运行此脚本,则可能遇到权限问题。为了解决这个问题,我建议一种不同的方法。

You may run into problems with permissions if you are running this script from a web server. To get around this, I would suggest a different approach.

这里是一个可能的解决方案。创建需要运行的脚本列表。您可以将其保存在文本文件或数据库中。创建一个脚本来读取此列表,并且每分钟或每5分钟运行一次(使用cronjob)。你的脚本需要足够聪明,以决定何时运行脚本列表,什么时候退出。

Here is one possible solution. Create a list of scripts that need to be run. You can save this in a text file or in a database. Create a script to read this list and run it every minute or every 5 minutes (using a cronjob). Your script will need to be smart enough to decide when to run the list of scripts and when to simply exit.

这篇关于如何通过PHP脚本设置cron作业的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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