PHP White Screen of Death Solution Guide

PHP White Screen of Death Solution Guide

One of the most infuriating things is when a PHP script fails, and there are no error messages on what happened. If you run your script and all you see is a white screen with no error messages you know the problem. It has been dubbed the PHP White Screen of Death, after the infamous Windows Blue screen of Death. Without error messages, it is almost impossible to fix a bug. Here is a guide on how to find the errors so you can actually fix a PHP white screen of death problem.

Set Error Reporting to All

Step one is the most basic and most easiest. At the beginning of your php script, put this at the top:

ini_set('display_errors', 1);

Look in Your Apache Logs

If that does not work, look in your Apache logs for errors. I use the Tail command to see the errors show up on the terminal as I reload the page.

tail -f /var/log/apache2/error.log

Search for the Error Suppression Character

The most likely culprit for not seeing errors is because someone used the Error Suppression Character(@). Do NOT use this character in your code! Ignoring errors is bad, and even if you ignore the error, it can still crash our program and give you no error message for you. You will probably get to many results from a grep search to actually find the culprit, but it is worth a try.

grep --include="*.php" "@" . -R

Find the Last Function Called

This is my last ditch effort, is to try and find the last function called to get close to the error. This has saved my behind a few times when all else fails. It uses the little know tick command to find out the last function called before PHP failed. Put this code at the beginning of your starting php script.

//start php counting ticks
function onTick(){
    //get the backtrace at the current tick
    $backtrace = debug_backtrace();
    //only store the file and line of the last function that run. debug_backtrace returns a lot of info, enough that it will grind your program to a halt
    $output = array(
        'file' =>   $backtrace[0]['file'],
        'line' => $backtrace[0]['line'],
    //this will only store the last function that run on the program. If that is enough to find the error, try using the FILE_APPEND flag to get a fuller picture
    file_put_contents('/tmp/backtrace.log', json_encode($output) );
//have the function onTick run every time a new function is called
register_tick_function('onTick', true);

Refresh your browser page running the script, and check the /tmp/backtrace file. It should get you in the vicinity of the error. If it does not, try to put the FILE_APPEND at the end of the file_put_contents function to get a more full picture of the flow of your program.

Hope this helps! If this helps you fix your PHP script, let me know in the comments.

No Comments

Leave a Comment

Please be polite. We appreciate that.
Your email address will not be published and required fields are marked