@@ -126,9 +126,14 @@ public function __construct(
126126 curl_setopt ($ ch , \CURLOPT_NOPROGRESS , false );
127127 curl_setopt ($ ch , \CURLOPT_PROGRESSFUNCTION , static function ($ ch , $ dlSize , $ dlNow ) use ($ onProgress , &$ info , $ url , $ multi , $ debugBuffer ) {
128128 try {
129+ $ info ['debug ' ] ??= '' ;
129130 rewind ($ debugBuffer );
130- $ debug = ['debug ' => stream_get_contents ($ debugBuffer )];
131- $ onProgress ($ dlNow , $ dlSize , $ url + curl_getinfo ($ ch ) + $ info + $ debug );
131+ if (fstat ($ debugBuffer )['size ' ]) {
132+ $ info ['debug ' ] .= stream_get_contents ($ debugBuffer );
133+ rewind ($ debugBuffer );
134+ ftruncate ($ debugBuffer , 0 );
135+ }
136+ $ onProgress ($ dlNow , $ dlSize , $ url + curl_getinfo ($ ch ) + $ info );
132137 } catch (\Throwable $ e ) {
133138 $ multi ->handlesActivity [(int ) $ ch ][] = null ;
134139 $ multi ->handlesActivity [(int ) $ ch ][] = $ e ;
@@ -209,14 +214,17 @@ public function getInfo(?string $type = null): mixed
209214 $ info ['starttransfer_time ' ] = 0.0 ;
210215 }
211216
217+ $ info ['debug ' ] ??= '' ;
212218 rewind ($ this ->debugBuffer );
213- $ info ['debug ' ] = stream_get_contents ($ this ->debugBuffer );
219+ if (fstat ($ this ->debugBuffer )['size ' ]) {
220+ $ info ['debug ' ] .= stream_get_contents ($ this ->debugBuffer );
221+ rewind ($ this ->debugBuffer );
222+ ftruncate ($ this ->debugBuffer , 0 );
223+ }
214224 $ waitFor = curl_getinfo ($ this ->handle , \CURLINFO_PRIVATE );
215225
216226 if ('H ' !== $ waitFor [0 ] && 'C ' !== $ waitFor [0 ]) {
217227 curl_setopt ($ this ->handle , \CURLOPT_VERBOSE , false );
218- rewind ($ this ->debugBuffer );
219- ftruncate ($ this ->debugBuffer , 0 );
220228 $ this ->finalInfo = $ info ;
221229 }
222230 }
0 commit comments