コード例 #1
0
ファイル: chatd.php プロジェクト: EmmanuelYupit/educursos
    echo "\n\n";
    echo "Usage: chatd.php [parameters]\n\n";
    echo "Parameters:\n";
    echo "  --start         Starts the daemon\n";
    echo "  -v              Verbose mode (prints trivial information messages)\n";
    echo "  -l [logfile]    Log all messages to logfile (if not specified, chatd.log)\n";
    echo "Example:\n";
    echo "  chatd.php --start -l\n\n";
    die;
}
if (!function_exists('socket_set_option')) {
    echo "Error: Function socket_set_option() does not exist.\n";
    echo "Possibly PHP has not been compiled with --enable-sockets.\n\n";
    die;
}
$DAEMON->init_sockets();
/*
declare(ticks=1);

$pid = pcntl_fork();
if ($pid == -1) {
     die("could not fork");
} else if ($pid) {
     exit(); // we are the parent
} else {
     // we are the child
}

// detatch from the controlling terminal
if (!posix_setsid()) {
   die("could not detach from terminal");
コード例 #2
0
ファイル: chatd.php プロジェクト: gabrielrosset/moodle
    echo "\n\n";
    echo "Usage: chatd.php [parameters]\n\n";
    echo "Parameters:\n";
    echo "  --start         Starts the daemon\n";
    echo "  -v              Verbose mode (prints trivial information messages)\n";
    echo "  -l [logfile]    Log all messages to logfile (if not specified, chatd.log)\n";
    echo "Example:\n";
    echo "  chatd.php --start -l\n\n";
    die;
}
if (!function_exists('socket_set_option')) {
    echo "Error: Function socket_set_option() does not exist.\n";
    echo "Possibly PHP has not been compiled with --enable-sockets.\n\n";
    die;
}
$daemon->init_sockets();
$daemon->trace('Started Moodle chatd on port ' . $CFG->chat_serverport . ', listening socket ' . $daemon->listen_socket, E_USER_WARNING);
// Clear the decks of old stuff.
$DB->delete_records('chat_users', array('version' => 'sockets'));
while (true) {
    $active = array();
    // First of all, let's see if any of our UFOs have identified itself.
    if ($daemon->conn_activity_ufo($active)) {
        foreach ($active as $handle) {
            $readsocket = array($handle);
            $write = null;
            $except = null;
            $changed = socket_select($readsocket, $write, $except, 0, 0);
            if ($changed > 0) {
                // Let's see what it has to say.
                $data = socket_read($handle, 2048);