Jump to content

stream_get_contents - very slow


ruraldev

Recommended Posts

I am using stream_get_contents and if I specify a length which is less than the stream length it returns the page quickly, if I use -1 or a value higher than the stream length it takes more than a minute!

 

Very slow versions

stream_get_contents($ras, 8000, -1);
stream_get_contents($ras, -1, -1);

 

Very quick

stream_get_contents($ras, 7500, -1);

 

The stream length varies so I don't have any idea what value will speed it up!

 

Any solutions?

Link to comment
https://forums.phpfreaks.com/topic/268571-stream_get_contents-very-slow/
Share on other sites

I should have just given the code

 

$ras = fsockopen($svr_add,$svr_port,$errno,$errstr,$svr_timeout);

fputs ($ras, $xml_data);

$ras1 = stream_get_contents($ras, -1, -1);

fclose($ras);

$startpos = strpos($ras1,'<',0);

$xml = substr($ras1,$startpos);

echo print_r($xml);

Managed to get it almost perfect, code below in case it helps anyone else.

 

$ras = stream_socket_client($svr_add,$errno,$errstr,$svr_timeout);

fputs ($ras, $xml_data);

stream_set_timeout($ras, 1);

$ras1 = stream_get_contents($ras, -1);

 

It takes 1 second but that's not a problem, I'll probably play with it to get the perfect timeout value.

 

Thanks for the help

 

Gordon

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.