@@ -418,43 +418,53 @@ public function getConnectTimeOut(): int
418
418
}
419
419
420
420
421
+ /**
422
+ * @param $handle
423
+ *
424
+ * @return bool
425
+ */
421
426
public function __findXClickHouseProgress ($ handle ): bool
422
427
{
423
- $ code = curl_getinfo ($ handle , CURLINFO_HTTP_CODE );
428
+ $ code = ( int ) curl_getinfo ($ handle , CURLINFO_HTTP_CODE );
424
429
425
430
// Search X-ClickHouse-Progress
426
- if ($ code == 200 ) {
431
+ if ($ code === 200 ) {
427
432
$ response = curl_multi_getcontent ($ handle );
428
- $ header_size = curl_getinfo ($ handle , CURLINFO_HEADER_SIZE );
429
- if (!$ header_size ) {
433
+ $ headerSize = curl_getinfo ($ handle , CURLINFO_HEADER_SIZE );
434
+ if (!$ headerSize ) {
430
435
return false ;
431
436
}
432
437
433
- $ header = substr ($ response , 0 , $ header_size );
434
- if (!$ header_size ) {
438
+ $ header = substr ($ response , 0 , $ headerSize );
439
+ if (!$ header ) {
435
440
return false ;
436
441
}
437
442
438
- $ pos = strrpos ($ header , 'X-ClickHouse-Summary: ' );
439
- if (!$ pos ) {
443
+ $ headerKeys = ['X-ClickHouse-Progress: ' , 'X-ClickHouse-Summary: ' ];
444
+ foreach ($ headerKeys as $ headerKey ) {
445
+ $ position = strrpos ($ header , $ headerKey );
446
+
447
+ if (false !== $ position ) {
448
+ break ;
449
+ }
450
+ }
451
+
452
+ if (false === $ position ) {
440
453
return false ;
441
454
}
442
455
443
- $ last = substr ($ header , $ pos );
444
- $ data = @json_decode (str_ireplace (' X-ClickHouse-Summary: ' , '' , $ last ), true );
456
+ $ last = substr ($ header , $ position );
457
+ $ data = @json_decode (str_ireplace ($ headerKey , '' , $ last ), true );
445
458
446
459
if ($ data && is_callable ($ this ->xClickHouseProgress )) {
447
-
448
460
if (is_array ($ this ->xClickHouseProgress )) {
449
461
call_user_func_array ($ this ->xClickHouseProgress , [$ data ]);
450
462
} else {
451
463
call_user_func ($ this ->xClickHouseProgress , $ data );
452
464
}
453
-
454
-
455
465
}
456
-
457
466
}
467
+
458
468
return false ;
459
469
}
460
470
0 commit comments