Good for staters. Nginx has nothing to do with this issue, which is understandable that PHP sends and receives data.
It is more than likely that your remote system is not closing the socket at the right time or just taking a long time to respond.
while (($chunk = socket_read($this->socket, 2048, PHP_BINARY_READ)) !== FALSE) { $response .= $chunk; if (substr($chunk, -1) == chr(27)) break; }
This code block can be an endless loop with this code if the remote system has not closed the connection / socket and told you about it, will try to read and wait for 2048 (bits or bytes - I can never remember what size it asks for the comment to report ) about the passage of data or about closing the socket before reading is completed.
So, a few things to try to reduce your read bytes, set it to something like 128 , put a timer in your socket (requires asynchronous programming in PHP), so kill it after 28 seconds, give your code 2 more seconds to execute ( safe exit). or use set_time_limit to increase the term.
If you increase your time limit, you will need to increase nginx time to get a response from connecting to PHP, to do this, set fastcgi_read_timeout
source share