Example #1
0
/**
* Handle a new client connection
*/
function handle_client($ssock, $csock)
{
    global $__server_listening;
    global $fh;
    global $firstInteraction;
    global $remip;
    global $remport;
    $pid = pcntl_fork();
    if ($pid == -1) {
        /* fork failed */
        //printLog($fh, "fork failure!");
        die;
    } elseif ($pid == 0) {
        /* child process */
        $__server_listening = false;
        socket_getpeername($csock, $remip, $remport);
        //printLog($fh, date("d-m-y h:i:sa") . " Connection from $remip:$remport");
        $firstInteraction = true;
        socket_close($ssock);
        interact($csock);
        socket_close($csock);
        printLog($fh, date("d-m-y h:i:sa") . " Connection to {$remip}:{$remport} closed");
        fecharArquivoLog();
    } else {
        socket_close($csock);
    }
}
Example #2
0
/**
 * Handle a new client connection
 */
function handle_client($ssock, $csock)
{
    global $__server_listening;
    global $fh;
    global $firstInteraction;
    global $remip;
    global $remport;
    $pid = pcntl_fork();
    if ($pid == -1) {
        /* fork failed */
        //printLog($fh, "fork failure!");
        die;
    } elseif ($pid == 0) {
        /* child process */
        $__server_listening = false;
        socket_getpeername($csock, $remip, $remport);
        //printLog($fh, date("d-m-y h:i:sa") . " Connection from $remip:$remport");
        $firstInteraction = true;
        // $send_cmd = "#88#DCST##\r\n";
        // socket_send($csock, $send_cmd, strlen($send_cmd), 0);
        // error_log('ENVIOU O COMANDO DCST');
        // error_log('SOCKET: '.$csock);
        // error_log('SEND CMD: '.$send_cmd);
        // $send_cmd = "#88#DCCM#6660000#5D##\r\n";
        // socket_send($csock, $send_cmd, strlen($send_cmd), 0);
        // error_log('ENVIOU O COMANDO DCCM 666');
        socket_close($ssock);
        interact($csock);
        socket_close($csock);
        printLog($fh, date("d-m-y h:i:sa") . " Connection to {$remip}:{$remport} closed");
        fecharArquivoLog();
    } else {
        socket_close($csock);
    }
}