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
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);

Link to comment
Share on other sites

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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.