# Displaying PHP Errors from admin-ajax.php

We've got some custom endpoints set up that do various things, which we access via /wp/wp-admin/admin-ajax.php?action=some_action

However whenever there is an error as we're developing, such as syntax, logical, fatal etc, we simply get "500 Internal Server Error"

Every other page on the site when there's an error, it gives us the PHP error.

We have to then open our PHP Log file to see the error.

Is there something in wordpress that disables displaying of errors on these URLs? and if so, how can we prevent this to allow rendering of the errors on the browser?

• If you look at the response in the network tab of the browser developer tools you’ll see the error. – Jacob Peattie Mar 26 '18 at 10:46
• That's the whole problem - we just get a "500 internal server error" response - regardless of how we get there, even if you load the url directly in your browser – Owen Mar 26 '18 at 12:09
• Please read this wordpress.stackexchange.com/questions/96554/… – bueltge Mar 26 '18 at 13:30
• @bueltge Sorry I've read it, but do not understand what is relevant? I cannot see anywhere that they are discussing why error messages do not render? – Owen Mar 26 '18 at 14:21
• Errors from ajax requests are never rendered in your browser directly. If error reporting is turned on you can see error messages in the network console. Bueltges link helps to debug that way. – Luckyfella Dec 14 '18 at 23:50

WordPress by default hide errors for ajax request call. This can be confirmed from the source file wp-includes/load.php#L353, here:

if ( defined( 'XMLRPC_REQUEST' ) || defined( 'REST_REQUEST' ) || ( defined( 'WP_INSTALLING' ) && WP_INSTALLING ) || wp_doing_ajax() ) {
@ini_set( 'display_errors', 0 );
}


See the function wp_doing_ajax() is being used in the conditional statement thus the display_errors is being set.

To workaround this, you need to turn on error reporting manually at top of your ajax function call as suggested by @Friss.

• THANK YOU!!! I know obviously you never want to hack the core, but in a local environment only for troubleshooting purposes only, when the ajax is being called by a plugin you don't want to mess with or have to time to figure out - temporarily commenting out the line noted above in /wp-includes/load.php will allow the output of more specific error messages and let you track down where the problem is coming from. – squarecandy Sep 25 at 19:58

You can try the WP_Ajax_Response

$response = array( 'what'=>'stuff', 'action'=>'delete_something', 'id'=>new WP_Error('oops','I had an accident.'), 'data'=>'Whoops, there was a problem!' );$xmlResponse = new WP_Ajax_Response($response);$xmlResponse->send();

• Sorry but this is not what we're asking for - our issue is that php errors are not displaying, when we need them to – Owen Mar 26 '18 at 12:10

You can try to add these two lines at the very top of tour script file

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


It tells php to report all kind of errors and overrides its default settings to display them.

• Hi, This does turn on error reporting - however, we're specifically trying to find out WHY it gets turned off for the admin-ajax.php as if we set it in the bottom of wp-config for example, it gets overwritten somewhere for the ajax calls – Owen Mar 27 '18 at 8:47