Answer the question
In order to leave comments, you need to log in
How to output JSON if PHP script execution duration is more than a certain value?
Hello! I have an API, I need to make it so that if processing a request to it takes more than 2 seconds, a json message is displayed. The API consists of nginx, php and mysql. JSON does not change, you can give a static file with it.
As I understand it, it is impossible to do this through php, because. the set_time_limit() function does not take into account the time of requests to mysql. I tried to do it through TimeOut in nginx and fpm, but I need the response code to be 200, not 504.
How can I implement this?
Answer the question
In order to leave comments, you need to log in
through nginx we set up the required timeout and catch 504 error
error_page 504 /504.json;
location /504.json{
add_header 'Content-Type' 'application/json charset=UTF-8';
return 200 '{"error": {"status_code": 200, "status": "Internal Server Error"}}';
}
transition on display does not work, and height must be set to the exact height, not auto. so either do it through js. or operate through max-height. first 0, then 1000px for example
https://jsfiddle.net/b0dxdou9/1/
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question