PHP produces a completely white page, no errors, logs, or headers.

断了今生、忘了曾经 提交于 2019-11-30 11:30:28

Run the page from a console and you'll get the error message.

// nix
php yourFile.php

// Windows
c:\path\to\php.exe yourFile.php

You could have a .htaccess file in this directory which has modified error reporting.

To test, try explicitly setting these options at the top of your php script which is giving you trouble.

ini_set('display_errors',1);
error_reporting(E_ALL);

I've also seen this caused by over-zealous anti-virus packages. Some contain web proxy software to filter internet and email. In that case, the page would just continue load into infinity but never complete.

Beware the @ (error suppression) operator, if you have a syntax error on a line with @ PHP will silently exit.

To detect this condition, use set_error_handler and write your own error handler, you'll still get called for errors where @ is used.

You say other PHP scripts are working, so that indicates it's probably not an Apache problem. You also appear to have all your logging settings correct, and nothing is getting logged, so it's quite possible PHP is exiting normally before it outputs anything. One of the following could be true:

  • A misplaced exit() statement? You were working on the code, maybe you added a quick exit() to check something out, and forgot to remove it?
  • don.neufeld's idea of checking for the use of the @ operator, which suppresses any error messages, has cost me hours of debugging time in the past. Definitely something to look for.

In situations like this, the poor man's debugging approach can yield some quick results. Throw an exit('wtf'); in as the first line in the script in question here. Does that run? The results of that test immediately rules out all sorts of possibilities no matter what the result is. If you don't get any output, then it's probably a server-level problem (configuration, bad module, etc), although be careful of any higher-level buffering. If you do get output, then you know the server is fine, and the issue lies deeper in your script, in which case you can move the exit() call down a few lines, rinse and repeat. Not an elegant way to debug, but it's quick and dirty, and you'll probably find the issue in a couple of minutes.

Check php.ini setting for short_open_tag = On or short_open_tag = Off

The most likely thing here is that apache is crashing. Look through the apache error log maybe, or attach a debugger.

Details on looking debugging the apache/php process on windows can be found at http://bugs.php.net/bugs-generating-backtrace-win32.php

I guessed the answer to this problem - it turns out that PHP 5.2.5 can't handle a recursive death.

<?php

class A
{
    public function __construct()
    {
        new B;
    }
}

class B 
{
    public function __construct()
    {
        new A;
    }
}

new A;

print 'Loaded Class A';

No headers, errors, content, logs, xdebug dumps, memory spikes, CPU spikes, server crashes, or anything. After about 150ms PHP just "ends". Weird.

To activate error display in your PHP code in case you don't see anything, insert

ini_set('display_errors',1); 
error_reporting(E_ALL);

Example where this potentialy saves you a lot of time:

This code in a joomla default.php template file displays a blank page with no error msg without lines 20 and 21

17  <?php if ($params->get('title_article_linkable')) { ?>
18      <a href="<?php 
19          $url = JRoute::_(ContentHelperRoute::getArticleRoute($item->id,$item->catid));
20          ini_set('display_errors',1);
21          error_reporting(E_ALL);
22          echo $url; ?>">
23      <?php echo $this->item->title; ?></a> // should be $item->title !!
24  <?phpLL000000 } else { ?>
25      <?php echo $item->title; ?>
26  <?php } ?>

Output:

check the Event Log.

When this happens, it is usually worth cutting out as much as possible of the code and seeing if you can get something on the page to show.

It could be due to an unclosed quote somewhere in your code, or an unclosed brace. This might cause the echo statement to be viewed as text or in another function, etc.

And, while all errors SHOULD be being reported, I have found that not all errors are actually reported, probably because of ini settings on a shared host that is out of my reach.

Commenting out is not always enough - not sure why not. When this happens, I usually find it to be quickest just to copy the page, and slowly cut and paste sections back in till I find the error, after which I can kick myself for a silly typo.

did you check your files for closing ?> tags? Or more importantly any whitespace after them...

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!