@@ -430,8 +430,10 @@ public function fastDownload($url, $filename, $connections = 4)
430
430
431
431
$ curl ->downloadCompleteCallback = function ($ instance , $ tmpfile ) use ($ part_file_name ) {
432
432
$ fh = fopen ($ part_file_name , 'wb ' );
433
- stream_copy_to_stream ($ tmpfile , $ fh );
434
- fclose ($ fh );
433
+ if ($ fh !== false ) {
434
+ stream_copy_to_stream ($ tmpfile , $ fh );
435
+ fclose ($ fh );
436
+ }
435
437
};
436
438
437
439
$ multi_curl ->addCurl ($ curl );
@@ -447,6 +449,9 @@ public function fastDownload($url, $filename, $connections = 4)
447
449
448
450
// Combine downloaded chunks into a single file.
449
451
$ main_file_handle = fopen ($ filename , 'w ' );
452
+ if ($ main_file_handle === false ) {
453
+ return false ;
454
+ }
450
455
451
456
foreach ($ part_file_names as $ part_file_name ) {
452
457
if (!is_file ($ part_file_name )) {
@@ -1031,7 +1036,7 @@ public function setHeaders($headers)
1031
1036
}
1032
1037
} else {
1033
1038
foreach ($ headers as $ header ) {
1034
- list ($ key , $ value ) = explode (': ' , $ header , 2 );
1039
+ list ($ key , $ value ) = array_pad ( explode (': ' , $ header , 2 ), 2 , '' );
1035
1040
$ key = trim ($ key );
1036
1041
$ value = trim ($ value );
1037
1042
$ this ->headers [$ key ] = $ value ;
@@ -1404,7 +1409,7 @@ public function diagnose($return = false)
1404
1409
if (isset ($ this ->responseHeaders ['Content-Length ' ])) {
1405
1410
echo 'Response content length (from content-length header): ' . $ response_header_length . "\n" ;
1406
1411
} else {
1407
- echo 'Response content length (calculated): ' . $ response_calculated_length . "\n" ;
1412
+ echo 'Response content length (calculated): ' . ( string ) $ response_calculated_length . "\n" ;
1408
1413
}
1409
1414
1410
1415
if (
@@ -1859,13 +1864,15 @@ private function downloadComplete($fh)
1859
1864
// Fix "PHP Notice: Use of undefined constant STDOUT" when reading the
1860
1865
// PHP script from stdin. Using null causes "Warning: curl_setopt():
1861
1866
// supplied argument is not a valid File-Handle resource".
1862
- if (!defined ('STDOUT ' )) {
1863
- define ('STDOUT ' , fopen ('php://stdout ' , 'w ' ));
1867
+ if (defined ('STDOUT ' )) {
1868
+ $ output = STDOUT ;
1869
+ } else {
1870
+ $ output = fopen ('php://stdout ' , 'w ' );
1864
1871
}
1865
1872
1866
1873
// Reset CURLOPT_FILE with STDOUT to avoid: "curl_exec(): CURLOPT_FILE
1867
1874
// resource has gone away, resetting to default".
1868
- $ this ->setFile (STDOUT );
1875
+ $ this ->setFile ($ output );
1869
1876
1870
1877
// Reset CURLOPT_RETURNTRANSFER to tell cURL to return subsequent
1871
1878
// responses as the return value of curl_exec(). Without this,
@@ -1881,13 +1888,16 @@ private function downloadComplete($fh)
1881
1888
*/
1882
1889
private function parseHeaders ($ raw_headers )
1883
1890
{
1884
- $ raw_headers = preg_split ('/\r\n/ ' , (string ) $ raw_headers , -1 , PREG_SPLIT_NO_EMPTY );
1885
1891
$ http_headers = new CaseInsensitiveArray ();
1892
+ $ raw_headers = preg_split ('/\r\n/ ' , (string ) $ raw_headers , -1 , PREG_SPLIT_NO_EMPTY );
1893
+ if ($ raw_headers === false ) {
1894
+ return ['' , $ http_headers ];
1895
+ }
1886
1896
1887
1897
$ raw_headers_count = count ($ raw_headers );
1888
1898
for ($ i = 1 ; $ i < $ raw_headers_count ; $ i ++) {
1889
1899
if (strpos ($ raw_headers [$ i ], ': ' ) !== false ) {
1890
- list ($ key , $ value ) = explode (': ' , $ raw_headers [$ i ], 2 );
1900
+ list ($ key , $ value ) = array_pad ( explode (': ' , $ raw_headers [$ i ], 2 ), 2 , '' );
1891
1901
$ key = trim ($ key );
1892
1902
$ value = trim ($ value );
1893
1903
// Use isset() as array_key_exists() and ArrayAccess are not compatible.
0 commit comments