Пример #1
0
        // We are the daemon! :P
    }

    // FROM NOW ON, IT'S THE DAEMON THAT'S RUNNING!

    // Detach from controlling terminal
    if(!posix_setsid()) {
        $DAEMON->trace('Could not detach daemon process from terminal!');
    }
}
else {
    // Cannot go demonic
    $DAEMON->trace('Unholy spirit possession failed: PHP is not compiled with --enable-pcntl');
}
*/
$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 has identified itself
    if ($DAEMON->conn_activity_ufo($active)) {
        foreach ($active as $handle) {
            $read_socket = array($handle);
            $write = null;
            $except = null;
            $changed = socket_select($read_socket, $write, $except, 0, 0);
            if ($changed > 0) {
                // Let's see what it has to say
                $data = socket_read($handle, 2048);
                // should be more than 512 to prevent empty pages and repeated messages!!