Closed as not planned
Description
Description
The following code (unchanged for years) is suddenly breaking in PHP 8.3.7 64bit NTS on IIS 10
<?php
$ch = curl_init();
$httpHeaders = array("Cache-Control: no-cache");
$postStr = "grant_type=authorization_code&code=REDACTED&redirect_uri=https%3A%2F%2Fwww.REDACTED.co.uk%2Ffoobar%2Fnhs-login%2F&client_id=REDACTED&client_assertion_type=urn%3Aietf%3Aparams%3Aoauth%3Aclient-assertion-type%3Ajwt-bearer&client_assertion=REDACTED";
if ($postStr != "") {
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $postStr);
}
curl_setopt($ch, CURLOPT_ENCODING, "");
curl_setopt($ch, CURLOPT_HTTPHEADER, $httpHeaders);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 30);
curl_setopt($ch, CURLOPT_TIMEOUT, $timeoutInSeconds);
curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-GB; rv:1.8.1.1) Gecko/20061204 Firefox/2.0.0.1");
$response->response = curl_exec($ch);
All of a sudden curl_exec() is returning false, more interestingly, curl_error($ch) returns an empty string!
Rolling back to PHP 8.3.3 fixes the problem and everything works as normal.
Digging a little deaper I added extra logging:
<?php
private function getCurlError($curlHandle) {
$ermsg = parseString(curl_error($curlHandle));
$ercode = parseString(curl_errno($curlHandle));
$ermsgcode = parseString(curl_strerror($ercode));
return "ErrorNo: " . $ercode . ", ErrorNoStr: " . $ermsgcode . ", " . $ermsg;
}
//#### Fetch Results
$response->responseCode = parseInt(curl_getinfo($ch, CURLINFO_HTTP_CODE));
//#### Check Results
if (!$response->response) {
$response->errorStr = "HTTP Error: CURL RETURNED FALSE (" . $this->getCurlError($ch) . ") with status code " . $response->responseCode . ": " . $url;
$response->result = false;
} elseif ($response->responseCode < 200 || $response->responseCode > 299) {
$response->errorStr = "HTTP Error: INVALID HTTP STATUS (" . $response->responseCode . " - expected 2xx): " . $url . " #### RESPONSE: " . $response->response;
$response->result = false;
} elseif (parseString($response->response) === "" || parseString($response->response) === "ERROR") {
$response->errorStr = "HTTP Error: BAD RESPONSE (" . $response->response . "): " . $url;
$response->result = false;
} else {
$response->response = parseString($response->response);
$response->result = true;
}
This gave me:
HTTP Error: CURL RETURNED FALSE (ErrorNo: 23, ErrorNoStr: Failed writing received data to disk/application, ) with status code 200
Note the http 200 - it looks like the CURL request is successfull, but CURL is returning false because of some disk writing issue?
PHP Version
PHP 8.3.7
Operating System
Windows 11 / WIndows Server 2016+