ruraldev Posted September 19, 2012 Share Posted September 19, 2012 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? Quote Link to comment Share on other sites More sharing options...
requinix Posted September 19, 2012 Share Posted September 19, 2012 The connection probably isn't being closed once all the data has been sent. What is this stream? Quote Link to comment Share on other sites More sharing options...
ruraldev Posted September 20, 2012 Author Share Posted September 20, 2012 I use fsockopen to make the connection and then send an xml command using fputs which makes the server return an xml string, the returned xml string varies in length. Quote Link to comment Share on other sites More sharing options...
ruraldev Posted September 20, 2012 Author Share Posted September 20, 2012 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); Quote Link to comment Share on other sites More sharing options...
Christian F. Posted September 20, 2012 Share Posted September 20, 2012 Perhaps this comment in the PHP manual will help, if not then you probably need to look at a different method for reading the data. Quote Link to comment Share on other sites More sharing options...
ruraldev Posted September 20, 2012 Author Share Posted September 20, 2012 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 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.