How can I set cron job through PHP script(如何通过 PHP 脚本设置 cron 作业)
问题描述
如何通过 PHP 脚本设置定时任务.
How can I set cron job through PHP script.
推荐答案
这将添加每天上午 9:30 运行的脚本.
This will add a script that runs every day at 9:30am.
exec('echo -e "`crontab -l`
30 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 作业的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:如何通过 PHP 脚本设置 cron 作业


基础教程推荐
- 在 yii2 中迁移时出现异常“找不到驱动程序" 2022-01-01
- 在 CakePHP 2.0 中使用 Html Helper 时未定义的变量 2021-01-01
- HTTP 与 FTP 上传 2021-01-01
- 找不到类“AppHttpControllersDB",我也无法使用新模型 2022-01-01
- 如何在 XAMPP 上启用 mysqli? 2021-01-01
- phpmyadmin 错误“#1062 - 密钥 1 的重复条目‘1’" 2022-01-01
- PHP 守护进程/worker 环境 2022-01-01
- 如何在 Symfony 和 Doctrine 中实现多对多和一对多? 2022-01-01
- Doctrine 2 - 在多对多关系中记录更改 2022-01-01
- 使用 PDO 转义列名 2021-01-01