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 作业


基础教程推荐
- 如何替换eregi() 2022-01-01
- YouTube API v3 点赞视频,但计数器不增加 2022-01-01
- 学说 dbal querybuilder 作为准备好的语句 2022-01-01
- 在PHP中根据W3C规范Unicode 2022-01-01
- Cron Jobs 调用带有变量的 PHP 脚本 2022-01-01
- PHP PDO MySQL 查询 LIKE ->多个关键词 2021-01-01
- 如何在 Laravel 5.3 注册中添加动态下拉列表列? 2021-01-01
- 如何在 Laravel 中使用 React Router? 2022-01-01
- PHP 类:全局变量作为类中的属性 2021-01-01
- 有什么方法可以用编码 UTF-8 而不是 Unicode 返回 PHP`json_encode`? 2021-01-01