-2

I have an api end point which receives some parameters and process them returns a csv file. But the processing time may take more than 15 seconds. My server has build in timeout and some client systems may have also timeout set.

How can I overcome this timeout issue with out changing any system settings?

I have gone through some articles, which says make a api call for registering the job, send back 202 response from server with a retry_after header, then process the data. Client resend api request after specified time, if process not complete repeat the cycle till process finish.

I don't know how to implement this in php. Any help will be appreciated...

2

The general principle here is fairly simple, and independent of programming language (PHP vs Java vs ...) and transport mechanism (HTTP vs message queues vs ...). When a request comes in to the API, determine the state of the request from your persistent store:

  1. Complete. Return the results and you're done.
  2. In progress. Return a "please wait" response to the client.
  3. Not started. Create a new record in your persistent store for the request, start processing the result in a background task of some kind and return "please wait" to the client.

A lot of the complexity in this sort of thing comes from the more precise requirements - for example, what counts as the same request? If two clients make a request with the same parameters, is that "the same request"? Similarly, you need to think about when to invalidate the cache of results - how important is it that clients get the absolutely very latest results as opposed to getting them quickly? These are all things for which there is no right answer - it depends on your specific use case.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.