Menu

#6 Ping is waiting forever

open
nobody
None
5
2014-07-23
2013-06-05
Mogyi
No

A small but very sensitive point on using Ping to keep connection alive. But when it goes offline we have to apply timeout on that request. Here is my quick hack, the solution could be more general.

function send_request($action, $parameters=array())
{
  $req = "Action: $action\r\n";
  foreach($parameters as $var=>$val)
    $req .= "$var: $val\r\n";
  $req .= "\r\n";
  fwrite($this->socket, $req);

  if ($action != 'Ping'){
    return $this->wait_response();
    } else {
    return $this->wait_response(TRUE);
    }
}

Discussion


Log in to post a comment.