程序员最近都爱上了这个网站  程序员们快来瞅瞅吧!  it98k网:it98k.com

本站消息

站长简介/公众号

  出租广告位,需要合作请联系站长

+关注
已关注

分类  

暂无分类

标签  

暂无标签

日期归档  

暂无数据

PHP 不能与 CRON 一起工作

发布于2023-01-18 01:57     阅读(1184)     评论(0)     点赞(30)     收藏(2)


I'm using crontab to call a php script.

In this script there is

error_log('test');

When the script is executed from http or direct command line like

php -f script.php

Everything is fine, my error is log.

But when called from cron it's not working.

Here is my cron

* * * * * -u www-data /full_path_to/php -f /full_path_to/script.php

Here is what I tried :

  • error_log with arguments :

    error_log('test', 3, '/full_path_to/error.log');
    
  • changing error reporting :

    error_reporting(E_ALL);
    ini_set('display_errors','On');
    ini_set('error_log', '/full_path_to/error.log');
    
  • cron call ending with > /full_path_to/error.log 2>&1 (don't know if useful)

For http the error_log path is set from htaccess. I'm lost with php cli...

I can see the cron execution working every minute (syslog), so it should be a PHP config problem ?

Thanks a lot if you can help.

Edit : Cron is executed with "-u www-data"

Here is the call I see in syslog :

CRON[13921]: (www-data) CMD (-u www-data /usr/bin/php -f /fullpath/script.php > /fullpath/error.log 2>&1)

解决方案


我实际上有两个问题:

1) 我的 cron 是用 php.ini for php-cli 执行的。我使用 -c 标志加载好的。

2) 我依赖 $_SERVER 使用 cli 模式中不存在的变量来声明重要常量。现在,如果未设置这些变量,我将解析命令行变量getopt()



所属网站分类: 技术文章 > 问答

作者:黑洞官方问答小能手

链接:http://www.phpheidong.com/blog/article/473610/22808858ceaa6c3dd586/

来源:php黑洞网

任何形式的转载都请注明出处,如有侵权 一经发现 必将追究其法律责任

30 0
收藏该文
已收藏

评论内容:(最多支持255个字符)