1

I created a PHP script to read the error log file in a customized visual format, but right now, I have the path to the error log file hard-coded in, which works fine for me, but I would like to find out if there's a way to pull the path to the error_log automatically so it can work on any server without further configuration.

1
  • So far, it seems like parsing phpinfo() to get the error log is going to be my best option. Commented Aug 1, 2011 at 15:35

3 Answers 3

1

You can use ini_get to obtain the error_log path in PHP.

$error_log = ini_get('error_log');

Otherwise, you'd be relegated to using something like:

<?php
ob_start();
phpinfo(INFO_CONFIGURATION);

$phpinfo = ob_get_contents();

ob_end_clean();

preg_match('#error_log</td><td\b[^>]*>(.*?)</td>#', $phpinfo, $matches);
$error_log = $matches[1];

Note that if there is no error_log set, $error_log will return:

<i>no value</i>
Sign up to request clarification or add additional context in comments.

Comments

0

you can pull it from the ErrorLog Directive

http://httpd.apache.org/docs/current/mod/core.html#errorlog

2 Comments

i would parse the file to find the string.
just found this, should answer most of your questions: cyberciti.biz/faq/apache-logs
0

The only way to get it in PHP is by installing something like ApacheAccessor. Wouldn't call it portable though, as I've seldomly seen it installed, but wildly guessing default paths is default distro's is about your only other option.

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.