php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #81448 file_get_contents cuts off incoming HTTP data
Submitted: 2021-09-16 15:57 UTC Modified: 2021-09-16 21:18 UTC
From: gajowy at agzeta dot pl Assigned:
Status: Open Package: HTTP related
PHP Version: 8.0.10 OS: Windows 10 64-bit
Private report: No CVE-ID: None
 [2021-09-16 15:57 UTC] gajowy at agzeta dot pl
Description:
------------
file_get_contents function can't get data from NASA servers. The server returns code 200 OK and data starts to be transmitted, however are cut off after some time (~120 seconds). It happens that data are transmitted correctly and the whole transmission takes app. 2 seconds in this case. 
The same request is working without any problem if curl is used.

It was tested on PHP 8.0.10 and 7.4.20 on 3 various (independend) networks.

Test script:
---------------
<?php
// ensure, that openssl extension is loaded
if( !extension_loaded('openssl') )
	exit("Please enable openssl extension in PHP.ini!\n");

$url="https://ssd.jpl.nasa.gov/api/horizons.api?format=text&COMMAND='00004%3B'&MAKE_EPHEM=YES&TABLE_TYPE=OBSERVER&CENTER='K80'&START_TIME=%272021-09-15+10%3A48%3A24+UT%27&STOP_TIME=%272021-09-16+10%3A48%3A24%27&STEP_SIZE=1m&REF_SYSTEM=J2000&QUANTITIES='1,3,4,19,20,21,23,25,8,9,33,38,43'&ANG_FORMAT=DEG&RANGE_UNITS=AU&APPARENT=REFRACTED&TIME_DIGITS=FRACSEC&EXTRA_PREC=YES&CSV_FORMAT=YES";

print("Running...\n");
$m0=microtime(TRUE);
$ret=file_get_contents($url);
printf("%d bytes downloaded in %.3f seconds\n",strlen($ret),microtime(TRUE)-$m0);

file_put_contents('query.txt',$url);
file_put_contents('header.txt',print_r($http_response_header,TRUE));
file_put_contents('document.txt',$ret);

?>

Expected result:
----------------
app. 480.000 bytes response is get. The output should end with a line with asterisks.

Actual result:
--------------
The output is cut of in various places, usually between 10k-200k of data.

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2021-09-16 15:58 UTC] gajowy at agzeta dot pl
The NASA server is nginx.
 [2021-09-16 21:18 UTC] cmb@php.net
I can confirm that there is an issue (PHP-7.4 on Windows).
Increasing default_socket_timeout doesn't help.
 [2023-01-09 09:47 UTC] fariba dot shami326 at gmail dot com
That's great. I was impressed by your writing. I am happy to see such a topic. Please come to my blog and read it.

(https://www.greenskyonline.me/)php.net
 [2024-06-12 10:03 UTC] blanca236tyndall at outlook dot com
Thanks for the info I will try to figure it out for more.(https://github.com)(https://www.my-fordbenefits.com)
 [2024-06-22 06:48 UTC] thomas642daniel at outlook dot com
Thanks for the info I will try to figure it out for more. (https://github.com)(https://www-costcoess.com)
 [2024-07-05 06:14 UTC] krina234pestro at outlook dot com
Website. It’s simple, yet effective.(https://github.com)(https://www.mycoveredcalifornia.com)
 [2024-07-08 04:52 UTC] krina234pestro at outlook dot com
Thank you for helping people get the information they need. Great stuff as usual. Keep up the great work!!! (https://github.com)(https://www.maxim-timeclock.com)
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sun Dec 22 01:01:30 2024 UTC