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
*
@@ -29,10 +31,55 @@ final class CurlClientState extends ClientState
29
31
/** @var float[] */
30
32
public $ pauseExpiries = [];
31
33
public $ execCounter = \PHP_INT_MIN ;
34
+ /** @var LoggerInterface|null */
35
+ public $ logger ;
32
36
33
37
public function __construct ()
34
38
{
35
39
$ this ->handle = curl_multi_init ();
36
40
$ this ->dnsCache = new DnsCache ();
37
41
}
42
+
43
+ public function reset ()
44
+ {
45
+ if ($ this ->logger ) {
46
+ foreach ($ this ->pushedResponses as $ url => $ response ) {
47
+ $ this ->logger ->debug (sprintf ('Unused pushed response: "%s" ' , $ url ));
48
+ }
49
+ }
50
+
51
+ $ this ->pushedResponses = [];
52
+ $ this ->dnsCache ->evictions = $ this ->dnsCache ->evictions ?: $ this ->dnsCache ->removals ;
53
+ $ this ->dnsCache ->removals = $ this ->dnsCache ->hostnames = [];
54
+
55
+ if (\is_resource ($ this ->handle ) || $ this ->handle instanceof \CurlMultiHandle) {
56
+ if (\defined ('CURLMOPT_PUSHFUNCTION ' )) {
57
+ curl_multi_setopt ($ this ->handle , \CURLMOPT_PUSHFUNCTION , null );
58
+ }
59
+
60
+ $ active = 0 ;
61
+ while (\CURLM_CALL_MULTI_PERFORM === curl_multi_exec ($ this ->handle , $ active ));
62
+ }
63
+
64
+ foreach ($ this ->openHandles as [$ ch ]) {
65
+ if (\is_resource ($ ch ) || $ ch instanceof \CurlHandle) {
66
+ curl_setopt ($ ch , \CURLOPT_VERBOSE , false );
67
+ }
68
+ }
69
+ }
70
+
71
+ public function __sleep ()
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
+ }
38
85
}
0 commit comments