Error in code results in admin-ajax.php 500 error

I don’t know if this is something recent that WordPress changed or not, but usually, when I was writing a function that is used as an action for ajax call (on front end), if I had some error in my code (missing ;, or unclosed } or whatever), I would get my ajax call returned in the Network tab in Chrome inspector, and when I’d select my admin-ajax.php and see the Preview or the Response tab, I’d see the error code written out.

Maybe a month ago or so, when I had an error in my code (I used undefined function in my callback function), all I got in the inspector was 500 error that pointed to the $.ajax() code in my .js script, with this

Read More

enter image description here

Nothing. I was sure this was a server issue, and send mails to my host, asking them about it. They didn’t know what it was either. Finally I found out that I can write my error messages with

ini_set('log_errors',TRUE);
ini_set('error_reporting', E_ALL);
ini_set('error_log', dirname(__FILE__) . '/error_log.txt');

and there I saw I had some errors in my callback function. Once I fixed that, the code worked.

But the thing is, usually I would see the error in my Response tab (or Preview). I’d see it, fix it and it worked.

I’m asking this because on some servers the above method with writing to error_log.txt takes a while. I am working on a client server that is on CentOS and error log appears in my wp root folder maybe 10 minutes or so after the error – which is not practical.

Did they change something in the core files regarding the ajax?

Related posts

1 comment

  1. This has nothing to do with the core files of WordPress, nothing have changed there.

    500 errors does not display any errors in the browser by default. This is based on the web server configuration, and not the wordpress installation.

    500 Errors will normally be found in the log files for the web server, normally located in

    /var/log/apache/error.log

    or

    /var/log/nginx/error.log

    These files should reflect any errors on the server immediately when they occur. So if you have a shell / ssh connection to your server, you could use a command like:

    tail -f /var/log/apache/error.log 
    

    This will give you a live feed of anything that is written to the file just when it happens.

    As for your INI_SET, these are php-commands that set default values for PHP. If you dont want to manually set these, you could update your PHP.ini file on your server with these variables, and they will be default for all sites on the server.

    Also, when in development on a wordpress site, you can update the wp-config.php and set the WP_DEBUG to true:

    define('WP_DEBUG', true);
    

Comments are closed.