You sometimes get a jQuery Ajax Error 500. The Homestead /var/logs/error.log will show you nothing and in your laravel.log nothing shows either. Fortunately in your console you did get an error and as it is a JavaScript or to be specific a jQuery Ajax error. So that is a start. But how to get to the bottom of this?
Background Information
As a heads up here some background information. We are using a Laravel Transip Package by Hidde. It is used to connect to a service provider (Transip) via a Soap API. And we use jQuery Ajax calls to make requests to this interface. We are working locally on a Laravel Homestead box and bumped into this error 500 issues and decided to dive deep into this package and the API provided by the service provider.
General jQuery Error
At first you will see the general error message and what functions it is related to (code modified somewhat names wise):
GET http://domain.test/backend/check-availability?querystring=value 500 (Internal Server Error) send @ jquery.min.js:4 ajax @ jquery.min.js:4 checkSomethingAvailability @ something-management?project=97:503 onclick @something-management?project=97:307
jQuery Send Error
With the JS beautified you can go to the line where the error occured. In this case line 4208 of jQuery formatted:
jquery.min.js:formatted:4208 GET http://domain.test/dashboard/check-domain-availability?domain=domain.io 500 (Internal Server Error) send @ jquery.min.js:formatted:4208 ajax @ jquery.min.js:formatted:3990 checkDomainAvailability @ domain-management?project=97:503 onclick @ domain-management?project=97:307
There you can see
g.send(b.hasContent && b.data || null)
and a cross next to it. When you hover on it you see this message
Failed to load resource: the server responded with a status of 500 (Internal Server Error)
So sending the data it failed to load something.
SoapFault
Then you decide to check the response for the actual file in the console by clicking the file under the Network Tab (Chrome Inspector):
That shows an exception. One that was not logged in the error log…. And there appears to be a SoapFault as you can see.
The actual error is this one:
(1/1) SoapFault Exception received from JSON Server: Timestamp outside maximum allowed window of 15 minutes; given timestamp was: 1518507112 (timestamp: 0.13471400 1520058610) in AbstractApi.php (line 36) at SoapClient->__call('checkAvailability', array('domain.com')) in AbstractApi.php (line 36) at AbstractApi->call('domainService', 'checkAvailability', array('domain.com')) in Domain.php (line 20) at Domain->checkDomain('domain.com') in DomainManagementController.php (line 81) at DomainManagementController->checkAvailability(object(Request), object(DomainManager)) at call_user_func_array(array(object(DomainManagementController), 'checkAvailability'), array(object(Request), object(TransIPManager))) in Controller.php (line 55) at Controller->callAction('checkAvailability', array(object(Request), object(TransIPManager))) in ControllerDispatcher.php (line 44) at ControllerDispatcher->dispatch(object(Route), object(DomainManagementController), 'checkAvailability') in Route.php (line 203) .......
AbstractApi Call
in AbstractApi.php of the Laravel package in question on line 36 mentioned in the error report we have
protected function call($service, $method, array $parameters = []) { return$this->getSoapClient($service, $method, $parameters)->__call($method, $parameters); }
public function checkAvailability($domainName) { return$this->call(self::SERVICE, 'checkAvailability', [$domainName]); }
JSON Server Exception
The Laravel API Package throws a SoapFault every time there is an issue making a connection. The username and key should be fine. I checked. The exception:
Exception received from JSON Server: Timestamp outside maximum allowed window of 15 minutes; given timestamp was: 1518507112 (timestamp: 0.13471400 1520058610)
Timezone Solution
Perhaps a timezone issue as Thomas at the Facebook PHP Group suggested. Logical when I think about it now, but well. So I did a
ln -sf /usr/share/zoneinfo/Europe/Amsterdam /etc/localtime
inside after.sh to make it Amsterdam time like the hoster, but it did not pick it up. And the Homestead date was February the 13th which was also completely off.
However when I did a:
sudo timedatectl set-timezone Europe/Amsterdam
inside the Vagrant Box and a hard reboot I got where I wanted to be. It did force me to do a service nginx restart
vagrant@homestead:~$ service nginx restart ==== AUTHENTICATING FOR org.freedesktop.systemd1.manage-units === Authentication is required to restart 'nginx.service'. Authenticating as: vagrant,,, (vagrant) Password: ==== AUTHENTICATION COMPLETE ===
to get things going.. However I go the CET time and correct date:
date Sat Mar 3 12:25:46 CET 2018
And once I had that all started working!
NB Funnily the Box was set to ‘timezone’ => ‘Europe/Amsterdam’, in config/app.php already..
Do you think this could possibly be my issue too? https://wordpress.stackexchange.com/questions/331093/repeating-admin-ajax-php-not-found-error-in-admin
I have little to no understanding of the servers or what it’s running, it’s a Dreamhost setup in the States and I’m using wordpress in the middle east on local time. All I know is they are upgrading to ubuntu bionic and mysql 5.7 next week. I found your article because I’m getting 400 and 500 errors at the same line 4208.
Thanks.
Hi Ed,
Do not think it is the same issue. But did you check what the actual error log stated on the error 500. Was there also really a 404 issue or a missing file when you checked the website via (S)FTP or ssh?
Hi Jasper,
Thanks for replying. The files are there and it seems to be called ok more than not. I did set the server times via ssh to run on local time via php.ini then reset the php scripts and reset the permalinks in wordpress but still see the issue so perhaps wasn’t that. I just found an error.log file (hope is correct one) as you suggested and it is full of the same warnings followed by same errors for all sorts of actions, an example is:
[Sat Mar 09 00:38:06 2019] [warn] [client 94.204.100.251] (104)Connection reset by peer: mod_fcgid: error reading data from FastCGI server, referer: https://www.mysite.com/wp-admin/
[Sat Mar 09 00:38:06 2019] [error] [client 94.204.100.251] Premature end of script headers: admin-ajax.php, referer: https://www.mysite.com/wp-admin/
This warn and error pattern repeats over and over in the error.log file but for lots of different referer url endings and different php files other than just admin-ajax.php eg plugins.php or index.php etc
Not sure how to approach fixing that, have sent ticket to host.
Dreamhost shared does throttle sites that use more memory than allowed. That could cause “Premature end of script headers” The error “Connection reset by peer: mod_fcgid: error reading data from FastCGI server: ” means that the fcgi dealing with processing of PHP bailed out. Perhaps Dreamhost needs to tweak fcgid.conf . But you cannot on shared nor VPS with them. And again this gets back to your site perhaps demanding more than they are willing to give and you were cut in RAM usage. You did however not tell me if you were on shared hosting. Test with P3 plugin will also be good to see if any plugin is hogging too much ram. That besides checking site for unusual activity with Wordfence doing a scan.
Yes it is shared hosting. I looked at the P3 plugin you suggested but I don’t think it works with php7, people say it has not been updated for over 4 yrs and is no longer viable. Dreamhost upgraded my sql and changed the memory limits to see if that helped but seemed to have no effect. Gutenburg editor has issues that don’t help maybe that is causing a ram overload when it hangs. I will ask the host to look at fcgid.conf ://github.com/WordPress/gutenberg/issues/9220 thanks