Morgan O'Neal
Morgan O'Neal

Reputation: 1118

How do you display php errors to the web browser in GAE?

Errors in Google App Engine are being suppressed and not displayed to the browser even if error reporting is on. The html that would normally be displayed to the browser is showing in the log files.

The following code should generate a error

<?php
  error
  phpinfo();
?>

When curling the page no content is returned just a 500 response code.

$ curl -i http://localhost/test.php

HTTP/1.1 500 Internal Server Error
Content-Type: text/html
Cache-Control: no-cache
Expires: Fri, 01 Jan 1990 00:00:00 GMT
Content-Length: 0
Server: Development/2.0
Date: Fri, 02 Aug 2013 18:24:49 GMT

The php.ini for this application has display_errors = On and phpinfo correctly shows when called from within the app.

The expected behavior is output like this

$ php-cgi54 test.php 

X-Powered-By: PHP/5.4.14
Content-type: text/html

<br />
<font size='1'><table class='xdebug-error xe-parse-error' dir='ltr' border='1' cellspacing='0' cellpadding='1'>
<tr><th align='left' bgcolor='#f57900' colspan="5"><span style='background-color: #cc0000; color: #fce94f; font-size: x-large;'>( ! )</span> Parse error: syntax error, unexpected 'phpinfo' (T_STRING) in /Users/example/test/test.php on line     <i>3</i></th></tr>
</table></font>

Upvotes: 1

Views: 2727

Answers (3)

Steren
Steren

Reputation: 7909

If your application exceptions should appear in your App Engine Logs, you can directly use Google Stackdriver Error Reporting to see at a glance the errors of your PHP application.

No setup is required since it is auto-configured for App Engine.

Access Error Reporting for your project at https://console.cloud.google.com/errors

Upvotes: 0

Stuart Langley
Stuart Langley

Reputation: 7054

In production we disable displaying errors for you app if it is being accessed by a normal user, for security reasons. This is regardless of the php.ini setting.

If the user accessing the app is one of the app administrators then we will display the errors to help you debug.

Of course, all errors are sent to the request log so you can go there and retrieve them.

Upvotes: 1

Travis Hegner
Travis Hegner

Reputation: 2495

I'm not sure if GAE will allow that through normal php directives.

You may be able to bypass it with:

<?php
function display_error($errno, $errstr, $errfile, $errline, $errcontext) {
  //echo desired info here
  die();
}

set_error_handler("display_error");
?>

GAE may block this as well, but it's pretty easy to give it a try

Edit:

More info on fatal errors, since that is the type of error you describe in your question, and may not be handled by set_error_handler(); How do I catch a PHP Fatal Error

Upvotes: 0

Related Questions