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


- 使用 GD 和 libjpeg 支持编译 PHP 2022-01-01
- 如何从数据库中获取数据以在 laravel 中查看页面? 2022-01-01
- 如何在 Symfony2 中正确使用 webSockets 2021-01-01
- 如何使用 Google API 在团队云端硬盘中创建文件夹? 2022-01-01
- Oracle 即时客户端 DYLD_LIBRARY_PATH 错误 2022-01-01
- PHP foreach() 与数组中的数组? 2022-01-01
- PHP - if 语句中的倒序 2021-01-01
- 覆盖 Magento 社区模块控制器的问题 2022-01-01
- openssl_digest vs hash vs hash_hmac?盐与盐的区别HMAC? 2022-01-01
- Laravel 5:Model.php 中的 MassAssignmentException 2021-01-01