socket_select

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
catalaur
Forum Newbie
Posts: 6
Joined: Sat Jul 15, 2006 2:00 pm

socket_select

Post by catalaur »

Weirdan | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]


Hi all. I have a problem with sockets. I wrote a script that connects to a dc hub. I want to close the connection when the socket stops reciving data from the server. I tryed to do this with socket_select but it doesn't work. I have this:

Code: Select all

$fp = fsockopen($hub_address, $hub_port, $errno, $errstr, $timeout);
if (!$fp) {
	echo "$errstr ($errno)<br />\n";
}else{
	echo "[+] Socket created<br>\n";
	echo "[+] Connected<br>\n";
	//ob_flush();
	//stream_set_blocking($fp, FALSE );
	//stream_set_timeout($fp, $timeout);
	//$status = socket_get_status($fp);
	$blank = 0;
	while(!feof($fp))
	{
		$out = fread($fp,4096);
		$r = array($out);
		if ($num_changed_stream = stream_select($r, $write = NULL, $except = NULL, 1) > 1)
		{
			echo 'reciving data from server';
		}
               .....
Warning: stream_select(): supplied argument is not a valid stream resource.
If anyone knows how to resolve this problem or he has another solution please post it here.
Regards!


Weirdan | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
User avatar
Weirdan
Moderator
Posts: 5978
Joined: Mon Nov 03, 2003 6:13 pm
Location: Odessa, Ukraine

Post by Weirdan »

stream_select accepts array of streams, perhaps you should handle $r = array($fp); to it.
catalaur
Forum Newbie
Posts: 6
Joined: Sat Jul 15, 2006 2:00 pm

Post by catalaur »

Yes maybe u're right but $out containes data from the socket....
Post Reply