tags:

views:

308

answers:

11

While running some PHP code on my private WAMP PC I'm suddenly getting a blank response from the server - no response actually. No headers, no data, nothing in the PHP error logs, nada. I restarted APACHE and PHP but still nothing. I know php is working because I can access other PHP scripts just fine.

Firebug reports no headers, ? bytes, and it only takes 163ms to "load" (so it's not a timeout). I thought about rapid memory consumption - but I monitored my PC's memory and it's not showing any spikes. Errors and Exceptions have been working fine until now.

What in the world?

max_execution_time = 30 ;
max_input_time = 60 ; 
max_input_nesting_level = 64 ; 
memory_limit = 500M ;

error_reporting = E_ALL | E_NOTICE | E_STRICT
display_errors = On
log_errors = On

:EDIT:

I wouldn't touch @ with a ten-foot-pole. I think the ruby guys through that in there so programmers would drop PHP.

Anyway, I enabled xdebug and it didn't output any grind files. Then I took zombat's advice and placed a DIE() at the top of the page and it worked. I guess that I just have some very weird code that totality kills PHP. Even if errors were disabled or suppressed with @ I should still be getting back a header from the server with the empty content!

If I find more I'll post back.

A: 

Can you post the code?

menkes
This should be a comment, not an answer. I already posted a comment to this effect.
Asaph
A: 

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

prodigitalson
+1  A: 

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.

txyoji
A: 

check the Event Log.

just somebody
A: 

Hi,

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

Asif
If short open tags were off then php would spill out into the rendered page. The page wouldn't be empty.
Mike B
+1  A: 

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

Eric Coleman
+1 though in the case of a crash he'll find a record in the Event Log. way easier than wrangling a debugger.
just somebody
Not at all a windows user, didn't know Event Log showed these things :) Thanks though.
Eric Coleman
+1  A: 

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.

Don Neufeld
+1 - the error suppression operator is a personal nemesis.
zombat
There is a pecl extension that can be used to help this particular problem.It's appropriately titled scream: http://pecl.php.net/scream
Eric Coleman
+2  A: 

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
Mike B
+1  A: 

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.

zombat
+1 awesome exit phrase
Xeoncross
A: 

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.

SamGoody
True, but even typos result in some form of an error.
Xeoncross
A: 

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.

Xeoncross
It's been fixed in PHP 5.3.0`Fatal error: Maximum function nesting level of '100' reached, aborting!`
Xeoncross
If you have the answer, you should mark this issue as resolved so that others do not waste their time trying to help you.
SamGoody
I can't, stackoverflow makes me wait accept it. In ten more hours I will be able to close it.
Xeoncross