My company is running an internal MediaWiki site on LAMP, which is actively used and has a number of custom modifications. Some users write really big DPL queries, and some of those queries actually exceed the configured memory limit per request.

The problem is that when PHP runs out of memory, it simply returns an HTTP error 500 and a blank page. I am trying to install a custom error handler which would return something useful to the user, e.g. "your query is too big and exceeded the alotted memory limit". I looked up the docs and found how it (supposedly) can be done; the problem is that the solution simply doesn't work. here is what i am trying to do:

PHP Code:
register_shutdown_function ('shutdown_handler');

function 
shutdown_handler () {
    
$err error_get_last();
    if (
$err && $err['type'] && ($err['type'] > 0) && ($err['type'] < 10)) {
    
error_reporting(-1);
    
ini_set('display_errors'1);
    
ini_set('display_startup_errors'1);
    
$message sprintf ("*** Error %s: %s\n"$err['type'], $err['message']);
    
error_log ($message);

    
header('HTTP/1.1 200'true); 
    
    print (
$message);

    
error_log ("Buffer contents:\n\n" ob_get_contents());

    
flush ();
    
ob_end_flush();
    exit ();
    }

Basically a lot of debug code in there. I trap the error, and i log all the pertinent into via the "error_log". I can set the response headers and HTTP code, and the browser receives it (in this case, I was setting it to 200 just because I felt like it). But no matter what I do, I cannot get any output to display to the user in their browser!

That "print" statement should work. The output string is in the buffer, I can see it in the buffer dump, and I am flushing the buffer -- but the browser simply receives no HTML content, nothing. Blank page.

Any ideas?