-1

A Drupal website is using external Rest API service.

The problem is that in a rare occasion when the Rest API service loses database or crashes for whatever reason, that causes the Drupal website to slow down.

Drupal uses many API endpoints frequently so when those are unavailable, the website becomes useless.

What would be a reliable or efficient way to check if the API is available prior to each request?

Thanks.

asked Oct 18, 2017 at 11:48
5
  • Can you give us a little more detail? Are these API requests part of the work on the server to generate the HTML file, or are these the result of AJAX requests? Are these built-in or custom Drupal Modules making these requests? Commented Oct 18, 2017 at 14:17
  • 1
    Those requests are aimed to another web server which hosts Rest API web service. Request are not fired from Javascript, only PHP. It's all about HTML as final result, but sorry, I don't quite understand your question. Commented Oct 18, 2017 at 14:28
  • Those are custom Modules. Commented Oct 18, 2017 at 16:05
  • The root cause is that you call an external system within synchronous user request. It kills reliability, scalability and more: medium.com/@wrong.about/… Commented Nov 2, 2017 at 7:50
  • "Drupal uses many API endpoints frequently so when those are unavailable, the website becomes useless." — This is inaccurate. Drupal doesn't talk to API endpoints by default. It sounds like this Drupal site was customized to be reliant on external APIs. That's probably what you meant, but the original phrasing makes it sound like it's Drupal's fault, which you probably didn't mean :) Also, @Zapadlo is exactly right. Commented Dec 30, 2017 at 0:17

1 Answer 1

1

First you need an alternate action for when the service is unavailable.

Then its just a matter of detecting the status of the service. Say, 5 calls time out in a 1 min period. Keep track of this stat and switch to your alternate method when it triggers.

Obvs. you want some automated way of switching it back on again of possible. Maybe a backend service to check every so often, or maybe just start sending requests again after a back off period.

answered Oct 18, 2017 at 13:24
6
  • Well, since API client uses Curl, I found out that I could set CURLOPT_CONNECTTIMEOUT and/or CURLOPT_TIMEOUT options. That seems like a better alternative. Commented Oct 18, 2017 at 14:07
  • 1
    I assumed you already had a timeout. the problem with this approach is that a reasonable timeout will slow your app down as each call waits for the timeout before continuing Commented Oct 18, 2017 at 14:10
  • Not quite following.. Are you saying that if I define timeout to, say 10 seconds, and if API responds in a fraction of a second, the Curl would be unavailable for another request until those 10 seconds pass? Commented Oct 18, 2017 at 14:15
  • 1
    no, but your code would wait 10sec before knowing the service wasnt available. presumably atm it waits the default 60sec. so its an improvement. Commented Oct 18, 2017 at 14:18
  • 1
    If this is possible (depends what service we're talking about) ,but maybe try to move request code to frontend , to jquery for example . Is service will not respond in a given time then you can produce some html output Commented Dec 27, 2017 at 21:41

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.