Fgets is slow. Is there any other method:
$fp = fsockopen($server, $port, $errno, $errstr ,30);fputs($fp, $send_all);stream_set_timeout($fp, 30);$result = '';while(!feof($fp)) { $result.= fgets($fp,1024);}print_r($result);
Although the data can be retrieved, it takes more than 20 seconds.
Is there any other way to read data? Do not use fread. use fread to retrieve complete data.
Reply to discussion (solution)
What about curl?
Slow because of network connection, unless the hardware environment is changed, how to change the code will not help
Slow because of network connection, unless the hardware environment is changed, how to change the code will not help
I read the documents and do not quite understand the principles of fread and fgets.
Fread can read all data at a time very quickly, but cannot obtain the complete data. it can only take more than one thousand bytes.
While fgets can get all of the 1024 values each time. It is very slow.
Does fgets need to be re-linked every time, so if there are more than a dozen cycles, it will slow down every time it is superimposed?
Fgets and fread are not directly involved in the connection. When packets arrive, they are stored in the buffer zone. they read the local buffer zone, so the speed is not affected.
Fread reads data blocks of the specified size until the end of the file. If the end of the file cannot be determined, a wait will occur, resulting in failure.
When fgets reads data blocks of the specified size, it will stop reading the data blocks with a line break until the end of the file.
Attackers can obtain remote data by using file_get_contents.
If your entire file is no larger than 8 kB, remove 1024.
The cause is found.
The MTU package on the server is limited.
Http://blog.csdn.net/jjjfew/article/details/6413460