php - php 脚本中的 Cron 不起作用

标签 php linux ubuntu cron

我已通过 file_put_contents 方法将 cron 作业添加到 php 脚本中的 /etc/crontab 文件中,但该 cron 未执行。如果我将此文件保存在 nano 编辑器中,cron 就可以工作。能否提示一下为什么php脚本添加的cron没有执行? 我尝试重新加载 cron 守护进程,但这没有帮助。 我使用文章 http://www.kavoir.com/2011/10/php-crontab-class-to-add-and-remove-cron-jobs.html 中的 cron 类.

我更改了方法saveJobs,用于将cron保存到文件/etc/crontab

static public function saveJobs($jobs = array()) {
    $output = file_put_contents('/etc/crontab', self::arrayToString($jobs));
    return $output;
}

添加cron的命令

Crontab::addJob("*/1 * * * * root php -f /var/www/get_all_clients_data_db.php ");

cron 记录已添加到 crontab,但该 cron 未执行。

/etc/crontab

# /etc/crontab: system-wide crontab
# Unlike any other crontab you don't have to run the `crontab'
# command to install the new version when you edit this file
# and files in /etc/cron.d. These files also have username fields,
# that none of the other crontabs do.

SHELL=/bin/sh
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin

# m h dom mon dow user  command
17 *    * * *   root    cd / && run-parts --report /etc/cron.hourly
25 6    * * *   root    test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.daily )
47 6    * * 7   root    test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.weekly )
52 6    1 * *   root    test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.monthly )
#
*/1 * * * * root php -f /var/www/get_all_clients_data_db.php

对于错误,我深表歉意。这是我在 StackOverflow 上的第一个问题。 提前致谢。

最佳答案

分享您的代码,很可能您缺少链接共享库错误。只需启用 crontab 日志记录并检查出现的确切错误。

有一个用于日志记录的命令行选项。输出保存到 screenlog.n 文件中,其中 n 是屏幕编号。从 screen 的手册页:

‘-L’告诉屏幕打开自动输出日志记录。

从屏幕启动程序并检查日志,了解其未运行的原因。

/usr/bin/screen -d -m -S -L CRMService /home/CRMService

如果您进一步陷入困境,请告诉我!

关于php - php 脚本中的 Cron 不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35079137/

相关文章:

linux - 在 Linux 中安装另一个 Perl?

c++ - VTK 未定义引用

php pconnect 与连接

linux - 根据其退出代码 bash 脚本将命令重定向到变量或文件?

php - Zend Db 使用 COLLATE 时出现非法排序规则和语法错误混合

linux - 使用 VC 和 MinGW

ubuntu - 如何组合两个 ffmpeg 命令 - 添加模糊条和添加 Logo 和字幕?

css - Arimo 字体似乎在任何地方都不起作用

php - 如何创建与 PHP 一起用于网页的模板

javascript - 错误 laravel 项目与 Blade SourceMap