I've attempting to fetch some json via cURL in PHP:
$params = array(
'need' => 'verify',
'access_token' => '123456789'
);
$paramsString = http_build_query($params);
$json_url = "http://localhost:8888/api/access-token-dummy.php";
$crl = curl_init();
curl_setopt($crl, CURLOPT_URL, $json_url);
curl_setopt($crl,CURLOPT_POST, count($params));
curl_setopt($crl,CURLOPT_POSTFIELDS, $paramsString);
$json = curl_exec($crl);
curl_close($crl);
$accessArray = json_decode($json, TRUE);
I was getting 504 Gateway Time-Out
from the url, which is local and didn't make sense to me. It definitely existed and was accessible from browsers. However, I noticed that once I attempted to request it via the above method as a cURL request in PHP 7, all other methods caused timeouts too (e.g. a refresh in a browser url that previously worked now returns a timeout) from after the point I tried this cURL request but not before (when the url would be fetched almost instantly, as expected).
It's an nginx 1.13.2 server and is hosting both the php making this request and the php url that the json is requested from. On top of this, I have a react server on a different port for the frontend. I mention this as I may have seen a reference before to this causing a conflict of sorts?
The CPU of the server never spikes and the url becomes accessible to browsers after a minute or two of waiting. It's never accessible via the cURL command, it always creates a timeout and prevents other requests for the next minute or two.
The URL contents being requested doesn't appear to matter. I've recreated it as minimally as the following and it still cause the same issue:
<?PHP
header('Content-type: application/json;charset=utf-8');
$returnArray = [];
$returnArray['message_user'] = "success";
$returnJSON = json_encode($returnArray);
echo $returnJSON;
?>
Nginx logs don't say too much but the following appears after the problem:
2020/10/22 17:00:23 [error] 52847#0: *49 upstream timed out (60: Operation timed out) while reading response header from upstream, client: 127.0.0.1, server: localhost, request: "POST /api/db-fetchurl.php HTTP/1.1", upstream: "nginxFastCGI.sock", host: "localhost:8888", referrer: "http://localhost:3000/requesturl"