Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/postgresql/10.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 动态添加cron作业_Php_Exec_Crontab - Fatal编程技术网

Php 动态添加cron作业

Php 动态添加cron作业,php,exec,crontab,Php,Exec,Crontab,我想通过将命令存储在文本文件中,然后在PHP代码中使用exec命令来动态添加cron作业 我的名为cron.txt的文本文件包含 */5 * * * * /usr/local/bin/php -f public_html/bookmark/email.php 我的相关PHP代码是 exec('crontab cron.txt', $a, $return); 当我运行代码时,$return被设置为错误代码1,并且没有添加cron作业。我以前做过,没有问题,但今天我错过了一些东西 确保Apach

我想通过将命令存储在文本文件中,然后在PHP代码中使用exec命令来动态添加cron作业

我的名为cron.txt的文本文件包含

*/5 * * * * /usr/local/bin/php -f public_html/bookmark/email.php
我的相关PHP代码是

exec('crontab cron.txt', $a, $return);

当我运行代码时,$return被设置为错误代码1,并且没有添加cron作业。我以前做过,没有问题,但今天我错过了一些东西

确保Apache用户(例如“www data”)或以CLI身份运行脚本的用户对cron.txt文件具有权限。

您是否尝试过类似的exec('crontab/path/to/cron.txt',$a,$return);
/var/log/apache2/error.log的输出是什么?您可能需要使用额外的权限运行PHP代码,可能是sudo。@Dr.Dan Yes尝试过这样做,相同result@Stegrex我对所有相关文件设置了777权限,但结果相同:(