fsockopen not closing an open connection correctly?
Posted: Sun Jun 04, 2006 10:37 am
I'm seeing some strange behaviour with fsockopen().
I'm doing something like this:
Basically, if I open a connection, send commands, then close it and open it again there's still data sitting in the socket which gets read wrongly when I'm using what I would expect to be a clean connection.
I need to be able to completely destroy the socket and create a completely clean/fresh start again but using the same variable names and references.
Is it my reference that's causing the problem? I need the reference since it gets used in several places and depending upon the method we use to connect the references may point to different things (too much to explain those reasons in the scope of this thread).
Any clues? The connection definitely closes, I've made sure of that because I get errors if I tgry to read while it's closed. But when it opens again something weird is happening.
I'm doing something like this:
Code: Select all
$sock = @fsockopen($host, $port, $errno, $errstr, $timeout);
$foo =& $sock;
fwrite($foo, $some_command); //Using reference
fgets($foo); //Using reference
fwrite($foo, $some_command);
// ** Not reading the response here because there sometimes isn't one **
fclose($sock); //Not by reference
$sock = false; //Just for safe measure
//Reconnect
$sock = @fsockopen($host, $port, $errno, $errstr, $timeout);
$foo =& $sock;
fwrite($foo, $some_command); //Using reference
fgets($foo); //Using reference
//It's reading data from the previous session wrongly?!!!I need to be able to completely destroy the socket and create a completely clean/fresh start again but using the same variable names and references.
Is it my reference that's causing the problem? I need the reference since it gets used in several places and depending upon the method we use to connect the references may point to different things (too much to explain those reasons in the scope of this thread).
Any clues? The connection definitely closes, I've made sure of that because I get errors if I tgry to read while it's closed. But when it opens again something weird is happening.