Пример #1
0
 /**
  * This static function initializes globals in the PHP Yate External Module.
  * It should be called before any other method.
  * @param $async (optional) True if asynchronous, polled mode is desired
  * @param $addr Hostname to connect to or UNIX socket path
  * @param $port TCP port to connect to, zero to use UNIX sockets
  * @param $role Role of this connection - "global" or "channel"
  * @return True if initialization succeeded, false if failed
  */
 static function Init($async = false, $addr = "", $port = 0, $role = "")
 {
     global $yate_stdin, $yate_stdout, $yate_stderr;
     global $yate_socket, $yate_debug, $yate_output;
     $yate_debug = false;
     $yate_stdin = false;
     $yate_stdout = false;
     $yate_stderr = false;
     $yate_output = false;
     if ($addr) {
         $ok = false;
         if ($port) {
             $yate_socket = @socket_create(AF_INET, SOCK_STREAM, SOL_TCP);
             $ok = @socket_connect($yate_socket, $addr, $port);
         } else {
             $yate_socket = @socket_create(AF_UNIX, SOCK_STREAM, 0);
             $ok = @socket_connect($yate_socket, $addr, $port);
         }
         if ($yate_socket === false || !$ok) {
             $yate_socket = false;
             $yate_stderr = fopen("php://stderr", "w");
             Yate::Output("Socket error, initialization failed");
             return false;
         }
         $yate_output = true;
     } else {
         $yate_socket = false;
         $yate_stdin = fopen("php://stdin", "r");
         $yate_stdout = fopen("php://stdout", "w");
         $yate_stderr = fopen("php://stderr", "w");
         $role = "";
     }
     flush();
     set_error_handler("_yate_error_handler");
     ob_implicit_flush(1);
     if ($async && function_exists("stream_set_blocking") && $yate_stdin) {
         stream_set_blocking($yate_stdin, false);
     }
     if ($role) {
         _yate_print("%%>connect:{$role}\n");
     }
     return true;
 }
Пример #2
0
 /**
  * Send a quit command to the External Module
  * @param close Set to true to close the communication immediately
  */
 static function Quit($close = false)
 {
     global $yate_stdin, $yate_socket;
     _yate_print("%%>quit\n");
     if ($close) {
         if ($yate_socket) {
             socket_close($yate_socket);
             $yate_socket = false;
         } else {
             if ($yate_stdin) {
                 fclose($yate_stdin);
                 $yate_stdin = false;
             }
         }
     }
 }