Skip to content

Commit 0d63468

Browse files
committed
Fix use of the deprecated function curl_close()
1 parent e616f11 commit 0d63468

File tree

2 files changed

+72
-70
lines changed

2 files changed

+72
-70
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,12 @@ All notable changes to this project will be documented in this file. This projec
44
to [Semantic Versioning] (http://semver.org/). For change log format,
55
use [Keep a Changelog] (http://keepachangelog.com/).
66

7+
## [2.5.1] - 2026-01-13
8+
9+
### Fixed
10+
11+
- Use of the deprecated function curl_close()
12+
713
## [2.5.0] - 2025-10-14
814

915
### Added

src/Adapter/CurlAdapter.php

Lines changed: 66 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -128,82 +128,78 @@ public function sendRequest(RequestInterface $request, ?HttpContext $context = n
128128
$ch = curl_init();
129129
curl_setopt_array($ch, $curlOptions);
130130

131-
try {
132-
// Execute CURL request
133-
$dateTime = new DateTimeImmutable();
134-
curl_exec($ch);
131+
// Execute CURL request
132+
$dateTime = new DateTimeImmutable();
133+
curl_exec($ch);
135134

136-
// CURL error?
137-
switch (curl_errno($ch)) {
138-
case CURLE_OK:
139-
break;
140-
case CURLE_URL_MALFORMAT:
141-
case CURLE_URL_MALFORMAT_USER:
142-
case CURLE_MALFORMAT_USER:
143-
case CURLE_BAD_PASSWORD_ENTERED:
144-
throw new RequestException(
145-
sprintf(
146-
'CURL error: %s (%s)',
147-
curl_error($ch),
148-
$request->getUri()
149-
),
150-
$request
151-
);
152-
default:
153-
throw new NetworkException(
154-
sprintf(
155-
'CURL error: %s (%s)',
156-
curl_error($ch),
157-
$request->getUri()
158-
),
159-
$request
160-
);
161-
}
135+
// CURL error?
136+
switch (curl_errno($ch)) {
137+
case CURLE_OK:
138+
break;
139+
case CURLE_URL_MALFORMAT:
140+
case CURLE_URL_MALFORMAT_USER:
141+
case CURLE_MALFORMAT_USER:
142+
case CURLE_BAD_PASSWORD_ENTERED:
143+
throw new RequestException(
144+
sprintf(
145+
'CURL error: %s (%s)',
146+
curl_error($ch),
147+
$request->getUri()
148+
),
149+
$request
150+
);
151+
default:
152+
throw new NetworkException(
153+
sprintf(
154+
'CURL error: %s (%s)',
155+
curl_error($ch),
156+
$request->getUri()
157+
),
158+
$request
159+
);
160+
}
162161

163-
// Timings
164-
$this->timings = new Timings(
165-
dateTime: $dateTime,
166-
send: (float)((curl_getinfo($ch, CURLINFO_PRETRANSFER_TIME_T)
167-
- curl_getinfo($ch, CURLINFO_APPCONNECT_TIME_T)) / 1000),
168-
wait: (float)((curl_getinfo($ch, CURLINFO_STARTTRANSFER_TIME_T)
169-
- curl_getinfo($ch, CURLINFO_PRETRANSFER_TIME_T)) / 1000),
170-
receive: (float)((curl_getinfo($ch, CURLINFO_TOTAL_TIME_T)
171-
- curl_getinfo($ch, CURLINFO_STARTTRANSFER_TIME_T)) / 1000),
172-
total: (float)(curl_getinfo($ch, CURLINFO_TOTAL_TIME_T) / 1000),
173-
blocked: -1,
174-
dns: (float)(curl_getinfo($ch, CURLINFO_NAMELOOKUP_TIME_T) / 1000),
175-
connect: (float)((curl_getinfo($ch, CURLINFO_CONNECT_TIME_T)
176-
- curl_getinfo($ch, CURLINFO_NAMELOOKUP_TIME_T)) / 1000),
177-
ssl: (float)((curl_getinfo($ch, CURLINFO_APPCONNECT_TIME_T)
178-
- curl_getinfo($ch, CURLINFO_CONNECT_TIME_T)) / 1000),
179-
);
162+
// Timings
163+
$this->timings = new Timings(
164+
dateTime: $dateTime,
165+
send: (float)((curl_getinfo($ch, CURLINFO_PRETRANSFER_TIME_T)
166+
- curl_getinfo($ch, CURLINFO_APPCONNECT_TIME_T)) / 1000),
167+
wait: (float)((curl_getinfo($ch, CURLINFO_STARTTRANSFER_TIME_T)
168+
- curl_getinfo($ch, CURLINFO_PRETRANSFER_TIME_T)) / 1000),
169+
receive: (float)((curl_getinfo($ch, CURLINFO_TOTAL_TIME_T)
170+
- curl_getinfo($ch, CURLINFO_STARTTRANSFER_TIME_T)) / 1000),
171+
total: (float)(curl_getinfo($ch, CURLINFO_TOTAL_TIME_T) / 1000),
172+
blocked: -1,
173+
dns: (float)(curl_getinfo($ch, CURLINFO_NAMELOOKUP_TIME_T) / 1000),
174+
connect: (float)((curl_getinfo($ch, CURLINFO_CONNECT_TIME_T)
175+
- curl_getinfo($ch, CURLINFO_NAMELOOKUP_TIME_T)) / 1000),
176+
ssl: (float)((curl_getinfo($ch, CURLINFO_APPCONNECT_TIME_T)
177+
- curl_getinfo($ch, CURLINFO_CONNECT_TIME_T)) / 1000),
178+
);
180179

181-
// Response
182-
$protocolVersion = $reasonPhrase = null;
183-
$bodyStream->seek(0);
184-
$headers = $this->parseHeaders(
185-
$headersStream->getContents(),
186-
protocolVersion: $protocolVersion,
187-
reasonPhrase: $reasonPhrase
188-
);
180+
// Response
181+
$protocolVersion = $reasonPhrase = null;
182+
$bodyStream->seek(0);
183+
$headers = $this->parseHeaders(
184+
$headersStream->getContents(),
185+
protocolVersion: $protocolVersion,
186+
reasonPhrase: $reasonPhrase
187+
);
189188

190-
// Replace location header with redirect_url parameter
191-
if (!empty($redirectUrl = curl_getinfo($ch, CURLINFO_REDIRECT_URL))) {
192-
$headers['Location'] = [$redirectUrl];
193-
}
189+
// Replace location header with redirect_url parameter
190+
if (!empty($redirectUrl = curl_getinfo($ch, CURLINFO_REDIRECT_URL))) {
191+
$headers['Location'] = [$redirectUrl];
192+
}
194193

195-
// Create response
196-
$response = new Response(
197-
$this->createStream($bodyStream, $headers['Content-Encoding'] ?? null),
198-
curl_getinfo($ch, CURLINFO_RESPONSE_CODE),
199-
$headers,
200-
$reasonPhrase ?? ''
201-
);
194+
// Create response
195+
$response = new Response(
196+
$this->createStream($bodyStream, $headers['Content-Encoding'] ?? null),
197+
curl_getinfo($ch, CURLINFO_RESPONSE_CODE),
198+
$headers,
199+
$reasonPhrase ?? ''
200+
);
202201

203-
return $response->withProtocolVersion($protocolVersion);
204-
} finally {
205-
curl_close($ch);
206-
}
202+
return $response->withProtocolVersion($protocolVersion);
207203
}
208204

209205
/**

0 commit comments

Comments
 (0)