Hi,
I'm writing some classes that communicate with a telnet like service.
It all seemed to go well. I got a connection, no timeout. My commands were accepted, and I got an answer.
The only problem is: It takes too #*#$#$ing long!!!
Does anyone have any idea why there's no feof and why the \n is not being recognized?
Check out this output. The numbers are the time in seconds.
start: 1055345500.08
tussen: 1055345500.33
1055345500.38: '220 blahdiblah Wed, 11 Jun 2003 15:31:42 GMT - Service ready
' // notice the \n here
1055345500.38: '.
'
1055345560.38: ''
1055345620.37: ''
1055345680.38: ''
1055345740.38: ''
1055345800.37: ''
1055345860.38: ''
One minute interval returning nothing.
I tried using fread, even 1 byte a time and anything I thought might make a difference.
The most shocking part is the fact that the $res != ".\n" doesn't work!!!
Here's the code:
<?
// fragment of a class
$this->debug( "start: ".lib_some::getmicrotime());
$this->conn = fsockopen($this->server, $this->port, $errno, $errstr, $this->timeout);
$this->debug( "tussen: ".lib_some::getmicrotime());
//if( $this->conn and $this->conn_ok() ){
if( $this->conn and $this->conn_ok()){
$this->debug( "uitslag: ".lib_some::getmicrotime());
$this->connected = true;
$this->debug("verbinding ok");
} // and so on
?>
<?
//The functions used:
function conn_ok(){
if($this->get_response($response)){
if (ereg("^[0123]{3}", $response)) {
return true;
} else {
return false;
}
}else{
return false;
}
}
function get_response(&$response){
if (!$this->conn) {
return false;
}
$response = "";
for($i = 0;($res != ".\n" and !feof($this->conn));$i++){
$res = fgets($this->conn);
echo lib_some::getmicrotime().": '".$res."'\n";
$response .= $res ;
flush();
}
return true;
}
?>