[TIP] Test TCP Port with PHP

September 26, 2008 | Filed Under Tips | No Comments

I need to test if specified TCP Port on specified Host is opened or Not, and i need to do it from a Web Service… This is my Solution a simple “ping” method written in PHP.

function qPing ($host, $port, $timeout = 5) {
    $socket = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);
    if ($socket === false) return(1);

    if (!socket_set_nonblock($socket))
        return(2);

    $time = time();
    while (!@socket_connect($socket, $host, $port)) {
        $err = socket_last_error($socket);
        if ($err == 115 || $err == 114) {
            if ((time() - $time) >= $timeout) {
                socket_close($socket);
                return(3);    # Connection timed out.
            }
            usleep(500);
            continue;
        }
        echo $err . ' ' . socket_strerror($err) . "\n";
        return(4);
    }

    socket_close($socket);
    return(0);
}

Quartica Image Theater

September 7, 2008 | Filed Under Qt4 | 1 Comment

I Really need a blackboard to fill with images, lines, rectangles and texts when i talk with someone. I think that is very useful when you’re trying to explain something something to someone.

Quartica Image Theater

Quartica Image Theater

This is the current status of Quartica Image Theater. Nice, But it could be more nicer. Suggestions are always accepted!