markwod Posted November 5, 2008 Share Posted November 5, 2008 Hi, I'm new to the PHP world. I've put together a simple script (below) with I intend to connect a server which sends out a stream of ASCII (I've a client in C++ with all works well). For now I just want it to read 250 bytes from the stream then somehow update a field on a brwoser. Which has lead me to these two questions: 1) Whist debugging, the script does connect and read bytes ok. But when I stop debugging PHP is still keeping the connection live, so when the script runs again it fails to work. I've found a few time out methods, all of which see to have now effect. 2) Presumably using some javascript or other. can anyone suggest a resource which will give me an idea on how to this data back to the browser (as it comes in) and update the field without user interaction. Many thanks Mark Link to comment https://forums.phpfreaks.com/topic/131497-sockets-streaming-to-a-browser-and-timing-out/ Share on other sites More sharing options...
markwod Posted November 5, 2008 Author Share Posted November 5, 2008 Code here sorry... <?php header("Cache-Control: no-cache, must-revalidate"); // Date in the past header("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); $host="www.somehere.co.uk" ; $port=8881; $timeout=5; $sk=fsockopen($host,$port,$errnum,$errstr,$timeout) ; stream_set_timeout($sk, 2); set_time_limit(10); if (!is_resource($sk)) { exit("connection fail: ".$errnum." ".$errstr) ; } else { $dati="" ; while (!feof($sk)) { $dati= fgets ($sk, 250); echo($dati) ; } } fclose($sk) ; //output the response echo($dati) ; ?> Link to comment https://forums.phpfreaks.com/topic/131497-sockets-streaming-to-a-browser-and-timing-out/#findComment-682957 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.