从shell运行脚本时,PHP error_log不记录日志

时间:2015-06-27 11:12:31

标签: php apache logging

这是一个基本的测试脚本,用于显示我遇到的问题:

test1.php

- (void)viewDidLoad
{
    [super viewDidLoad];

    self.skView = [[SKView alloc] init];
    [self.view addSubview:self.skView];

    SKScene2 *scene = [SKScene2 sceneWithSize:self.skView.bounds.size];
    scene.scaleMode = SKSceneScaleModeFill;
    [self.skView presentScene:scene];
}

这很好用。打开http://exmaple.com/test会记录下来'你好'到/var/log/apache2/error.log。

现在我有了这个,在后台运行test.php:

test2.php

<?php
     error_log('hello');
?>

我知道在此示例中<?php shell_exec("/usr/bin/php /var/www/test.php > /dev/null 2>/dev/null &"); ?> 被重定向到stderr,但我也在没有/dev/null的情况下尝试了它,但仍然没有记录。

我也尝试使用> /dev/null 2>/dev/null &

在test.php中设置error_log路径

有没有办法让它正确记录?

1 个答案:

答案 0 :(得分:0)

这对我有用

<?php
ini_set('error_log', '/home/user/error.log');
error_log('hello');

输出:

[27-Jun-2015 11:20:55 UTC] hello

确保从控制台运行脚本时有权写入日志文件。

相关问题