11
11
12
12
namespace Symfony \Component \HttpClient \Internal ;
13
13
14
+ use Psr \Log \LoggerInterface ;
15
+
14
16
/**
15
17
* Internal representation of the cURL client's state.
16
18
*
@@ -26,10 +28,58 @@ final class CurlClientState extends ClientState
26
28
public $ pushedResponses = [];
27
29
/** @var DnsCache */
28
30
public $ dnsCache ;
31
+ /** @var LoggerInterface|null */
32
+ public $ logger ;
29
33
30
34
public function __construct ()
31
35
{
32
36
$ this ->handle = curl_multi_init ();
33
37
$ this ->dnsCache = new DnsCache ();
34
38
}
39
+
40
+ public function reset ()
41
+ {
42
+ if ($ this ->logger ) {
43
+ foreach ($ this ->pushedResponses as $ url => $ response ) {
44
+ $ this ->logger ->debug (sprintf ('Unused pushed response: "%s" ' , $ url ));
45
+ }
46
+ }
47
+
48
+ $ this ->pushedResponses = [];
49
+ $ this ->dnsCache ->evictions = $ this ->dnsCache ->evictions ?: $ this ->dnsCache ->removals ;
50
+ $ this ->dnsCache ->removals = $ this ->dnsCache ->hostnames = [];
51
+
52
+ if (\is_resource ($ this ->handle ) || $ this ->handle instanceof \CurlMultiHandle) {
53
+ if (\defined ('CURLMOPT_PUSHFUNCTION ' )) {
54
+ curl_multi_setopt ($ this ->handle , \CURLMOPT_PUSHFUNCTION , null );
55
+ }
56
+
57
+ $ active = 0 ;
58
+ while (\CURLM_CALL_MULTI_PERFORM === curl_multi_exec ($ this ->handle , $ active ));
59
+ }
60
+
61
+ foreach ($ this ->openHandles as [$ ch ]) {
62
+ if (\is_resource ($ ch ) || $ ch instanceof \CurlHandle) {
63
+ curl_setopt ($ ch , \CURLOPT_VERBOSE , false );
64
+ }
65
+ }
66
+
67
+ curl_multi_close ($ this ->handle );
68
+ $ this ->handle = curl_multi_init ();
69
+ }
70
+
71
+ public function __sleep (): array
72
+ {
73
+ throw new \BadMethodCallException ('Cannot serialize ' .__CLASS__ );
74
+ }
75
+
76
+ public function __wakeup ()
77
+ {
78
+ throw new \BadMethodCallException ('Cannot unserialize ' .__CLASS__ );
79
+ }
80
+
81
+ public function __destruct ()
82
+ {
83
+ $ this ->reset ();
84
+ }
35
85
}
0 commit comments