Ticket #2880: phpagi-asmanager.php.diff

File phpagi-asmanager.php.diff, 1.5 kB (added by mickecarlsson, 3 years ago)

Diff file for the proposed patch

  • phpagi-asmanager.php

    old new  
    224224        $this->port = $this->config['asmanager']['port']; 
    225225      } 
    226226 
    227       // connect the socket 
     227      // connect the socket, set a 10 second timeout for the connection, this gives us plenty of time to connect 
    228228      $errno = $errstr = NULL; 
    229       $this->socket = @fsockopen($this->server, $this->port, $errno, $errstr); 
     229      $this->socket = @fsockopen($this->server, $this->port, $errno, $errstr, 10); 
    230230      if($this->socket == false) 
    231231      { 
    232232        $this->log("Unable to connect to manager {$this->server}:{$this->port} ($errno): $errstr"); 
    233233        return false; 
    234       } 
    235  
     234      } else 
     235      // Set a 2 second timeout for read/write commands 
     236      stream_set_timeout($this->socket, 2); 
     237   
    236238      // read the header 
    237239      $str = fgets($this->socket); 
    238240      if($str == false) 
     
    251253      if($res['Response'] != 'Success') 
    252254      { 
    253255        $this->log("Failed to login."); 
    254         $this->disconnect(); 
     256        $this->disconnect(TRUE); 
    255257        return false; 
    256258      } 
    257259      return true; 
     
    262264    * 
    263265    * @example examples/sip_show_peer.php Get information about a sip peer 
    264266    */ 
    265     function disconnect(
     267    function disconnect($dontlogoff=NULL
    266268    { 
     269      if (!$dontlogoff) 
    267270      $this->logoff(); 
    268271      fclose($this->socket); 
    269272    }