2

Here's a basic test script to show the issue I am having:

test1.php

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

This works fine. Opening http://exmaple.com/test will log 'hello' into /var/log/apache2/error.log.

Now I have this, to run test.php in the background:

test2.php

<?php
    shell_exec("/usr/bin/php /var/www/test.php > /dev/null 2>/dev/null &");
?>

I'm aware that the stderr is redirected to /dev/null in this example, but I have also tried it without > /dev/null 2>/dev/null & and still no logging occurs.

I did also try setting the error_log path in test.php using ini_set('error_log','/var/log/apache2/error.log');

Is there a way to get it to log correctly?

5
  • Hey, I just noticed StackOverflow changed their logo ... Is it Gay Pride week? Commented Jun 27, 2015 at 11:17
  • There was me trying to make a joke at the new logo ... And it actually is gay pride week ... Commented Jun 27, 2015 at 11:18
  • 2
    php when executed from CLI does not log to apaches log file. That would not make sense and most likely it does not have permission to do so. Typically there are separate php.ini files for cli and http server mode. And typically php on cli logs to stderr. Which you do not pick up in the code above. Commented Jun 27, 2015 at 11:24
  • @arkascha It doesn't log to apache log files by default. I tried the code from the answer, and it worked. Commented Jun 27, 2015 at 11:25
  • I am pretty sure that your attempt with ini_set('error_log','/var/log/apache2/error.log'); does refer to an apache log file. Which typically will not work as mentioned because of file permissions. Commented Jun 27, 2015 at 11:37

1 Answer 1

1

This worked for me

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

Output:

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

Make sure, that you have permission to write into the log file when you run the script from console.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.