问题描述
如何通过 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 作业的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!



大气响应式网络建站服务公司织梦模板
高端大气html5设计公司网站源码
织梦dede网页模板下载素材销售下载站平台(带会员中心带筛选)
财税代理公司注册代理记账网站织梦模板(带手机端)
成人高考自考在职研究生教育机构网站源码(带手机端)
高端HTML5响应式企业集团通用类网站织梦模板(自适应手机端)