You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

68 lines
1.4 KiB

<?php
include_once 'util/util.php';
$debugSck = 0;
function ConnectSck($host, $porta) {
$timeout = 10;
$errno = '';
$errstr = '';
$socket = fsockopen($host, $porta, $errno, $errstr, $timeout);
if (!$socket) {
GeraExcept("N<EFBFBD>o foi poss<EFBFBD>vel conectar ao servidor! Erro: [$errno] [$errstr]\n");
}
return $socket;
}
function ReadSckl($socket, $endCmd = array()) {
$str = '';
$buffer = '';
if (!$socket) {
GeraExcept("N<EFBFBD>o <EFBFBD> poss<EFBFBD>vel ler o socket! Socket inv<EFBFBD>lido\n");
}
while (!feof($socket)) {
$str = trim(@fgets($socket));
$buffer .= $str;
if (array_search($str, $endCmd)) {
return $buffer;
}
}
return $buffer;
}
function DisconnectSck($socket) {
fclose($socket);
}
function WriteSck($socket, $value, $function = '', $logOnly = false) {
global $debugSck;
$write = 0;
if (!$socket) {
GeraExcept("N<EFBFBD>o <EFBFBD> poss<EFBFBD>vel escrever no socket! Socket inv<EFBFBD>lido\n");
}
if (!$logOnly) {
$write = fwrite($socket, $value, strlen($value));
}
if ($debugSck) {
$path = "/var/log/asterisk/log_sck.log";
if ($function) {
GravaLog("\n[$function]\n", $path);
}
if ($value) {
GravaLog($value, $path);
}
}
return $write;
}
?>