Logging PHP errors

Hi Experts,

I am using WordPress and I believe one of my plugins is throwing fatal PHP errors.
But these errors are not showing up in my PHP error log.

Here are the current PHP settings reported by phpinfo():


Directive	Local Value	Master Value
display_errors	Off	Off
display_startup_errors	Off	Off
error_append_string	</font>	</font>
error_log	no value	no value
error_prepend_string	<font color=ff0000>	<font color=ff0000>
error_reporting	32767	32767
log_errors	On	On
log_errors_max_len	1024	1024
track_errors	Off	Off

Open in new window


What changes do I need to make so that all error levels are included in my PHP error log?
Also what is the difference between Local Value and Master Value?

Regards,
Leigh
LVL 1
LeighWardleAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Dave BaldwinFixer of ProblemsCommented:
It looks like you do not have an 'error_log' file defined.  http://php.net/manual/en/errorfunc.configuration.php#ini.error-log  And set 'error_reporting' to max. http://php.net/manual/en/errorfunc.configuration.php#ini.error-reporting

I don't know about Local Value and Master Value because on my accounts they are always the same.
0
LeighWardleAuthor Commented:
Hi Dave,

Sorry, I had not mentioned earlier, there already appears to an 'error_log' file active, with contents like this:

PHP Warning:  Module 'json' already loaded in Unknown on line 0
PHP Warning:  Module 'sockets' already loaded in Unknown on line 0
PHP Warning:  Module 'mbstring' already loaded in Unknown on line 0
PHP Warning:  Module 'json' already loaded in Unknown on line 0
PHP Warning:  Module 'mysqlnd' already loaded in Unknown on line 0
PHP Warning:  Module 'mysql' already loaded in Unknown on line 0
PHP Warning:  Module 'mysqlnd' already loaded in Unknown on line 0
PHP Warning:  Module 'mysqli' already loaded in Unknown on line 0
PHP Warning:  Module 'mysqlnd' already loaded in Unknown on line 0
PHP Warning:  Module 'PDO' already loaded in Unknown on line 0
PHP Warning:  Module 'pdo_mysql' already loaded in Unknown on line 0
PHP Warning:  Module 'PDO' already loaded in Unknown on line 0
PHP Warning:  Module 'json'
PHP Warning:  PHP Startup: Unable to load dynamic library
'/opt/alt/php55/usr/lib64/php/modules/ffmpeg.so' - libswscale.so.2:
cannot open shared object file: No such file or directory in Unknown on
line 0

Open in new window


So I assume it is already logging Warnings, but not higher level errors?
0
Dave BaldwinFixer of ProblemsCommented:
Yes, but the only way you get those warnings is to have those extensions defined twice in 'php.ini'.  Are you on Windows or Linux?
0
Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

LeighWardleAuthor Commented:
I'm on a Linux-based website hosting service.
0
Dave BaldwinFixer of ProblemsCommented:
Do you have your own 'php.ini' in your web space?
0
LeighWardleAuthor Commented:
No, I don't have my own 'php.ini' in my web space.
I guess I will have ask my host to make the changes?
0
Dave BaldwinFixer of ProblemsCommented:
You should ask them why you are getting those warnings about the extensions being already loaded.
0
Ray PaseurCommented:
assume it is already logging Warnings, but not higher level errors?
That may miss the point.  PHP error logging should log all Notice, Warning and Error messages, as well as anything written to the error log file with the PHP error_log() function.  Your PHP installation may have been logging "once upon a time" but the current installation / initialization settings have turned it off.  You can test this.  Just run the following script, and look in the error log file.  If you find both messages, you know that error logging is currently working.
<?php 
$now = date('c');
error_log("THIS IS A TEST OF THE ERROR LOG $now");
trigger_error("THIS IS A TEST OF THE TRIGGER ERROR $now", E_USER_ERROR);

Open in new window

In a properly configured PHP installation, you can affect error reporting, display and logging at run time.  And you may want to, because the standard PHP installation suppresses Notice messages, a terrible practice that can cause your scripts to rely on undefined variables without any notice, resulting in all kinds of unpredictable behavior.  This works for me on my server.  After you test the script above, try putting these settings into the top of the script and test it again.
<?php
ini_set('display_errors', TRUE);
ini_set('log_errors',     TRUE);
error_reporting(E_ALL);

Open in new window

The difference between "master setting" and "local setting" tells you what the server is using as its "default" setting and what the current script is using as its implementation setting.  Here are some php.ini settings that should be helpful.  It looks like your master and local value for error_reporting are OK.
display_errors = On
log_errors = On
log_errors_max_len = 1024
error_log = error_log

Open in new window

And finally, here is a little script that I like to install on test systems.  It lets me find, read and delete error logs quickly and easily.   It's helpful, but could be a security exposure.  You might not want to leave it permanently in place, or you might want to password-protect it.
<?php // find_error_log.php
error_reporting(E_ALL);
ob_start();

// PUT THIS SCRIPT IN THE WEB ROOT DIRECTORY
$path = realpath(getcwd());
$plen = strlen($path);

// THE ERROR LOG FILE NAME
$signal = strrev('error_log');


// IF THERE IS A POST-METHOD REQUEST TO DELETE THIS ERROR LOG
if (!empty($_POST['log']))
{
    // MAKE SURE WE ONLY UNLINK THE ERROR LOG FILE
    $test = strrev($_POST['log']);
    if (strpos($test, $signal) === 0)
    {
        unlink($path . $_POST['log']);
        echo '<h3>' . $_POST['log'] . ' Discarded</h3>';
    }
}


// SEE http://php.net/manual/en/class.recursivedirectoryiterator.php#85805
$objs = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($path), RecursiveIteratorIterator::SELF_FIRST);

// UNFORTUNATELY THIS DOES NOT WORK AT PHP 5.4
// var_dump($objs);

// ITERATE OVER THE OBJECTS
foreach($objs as $name => $obj)
{
    // PROCESS THE ERROR LOG ONLY
    $test = strrev($name);
    if (strpos($test, $signal) === 0)
    {
        $name = substr($name, $plen);
        $form = <<<EOD
<form method="post" style="margin:0; padding:0; display:inline;!important">
<b>$name</b>
<input type="submit" value="Discard?" />
<input type="hidden" name="log" value="$name" />
</form>
EOD;
        echo $form;

        // SHOW THE CONTENTS OF THE ERROR LOG
        echo '<pre>';
        print_r(file_get_contents($path . $name));
        echo '</pre>' . PHP_EOL;
    }
}

$out = ob_get_contents();
if (empty($out)) echo '<h3>Good News! No error_log found.</h3>';

Open in new window

PHP should create the error_log file if one is needed and it does not exist.  So as a matter of practice when I'm debugging a system, I just delete the error_log, run my unit tests and look to see if the error_log is present after the tests.  It it's not there, I know that none of my tests threw an error.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
LeighWardleAuthor Commented:
Many Thanks, Dave & Ray.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
PHP

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.