我的 cronjob 实验需要帮助,我无法完成我想要的。以下是我所做的事情。
/var/www/html/bob/test/index.php
中创建一个 php 文件我的 index.php
<?php
$myfile = fopen("testfile.txt", "w");
?>
我对 的各种测试参数crontab -e 这没有用
*/1 * * * * root /usr/bin/php /var/www/html/bob/test/index.php
*/1 * * * * root /var/www/html/bob/test/index.php
*/1 * * * * root php -q /var/www/html/bob/test/index.php
*/1 * * * * root /var/www/html/bob/test/index.php
看着我的一些 /var/log/cron 我没有看到任何错误指示。
Sep 6 15:55:01 localhost CROND[4866]: (root) CMD (root /var/www/html/bob/test/index.php)
Sep 6 15:56:01 localhost CROND[4872]: (root) CMD (root /var/www/html/bob/test/index.php)
Sep 6 15:57:01 localhost CROND[4878]: (root) CMD (root /var/www/html/bob/test/index.php)
最后,当我通过
#php /var/www/html/bob/test/index.php
运行我的 php代码执行良好并创建该文本文件。
最佳答案
您需要删除 root
来自你的 cronjob。日志显示它正在尝试使用 /var/www/html/bob/test/index.php
执行名为 root 的程序。作为参数。
相反,请使用以下内容作为您的 cronjob:
*/1 * * * * /usr/bin/php /var/www/html/bob/test/index.php
This answer声明如果要设置运行 cronjob 的用户,则必须编辑
/etc/crontab
直接,而不是使用 crontab -e
.
关于php - 在centos上的cron作业中执行PHP,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46070019/