private static function validateUrl($link)
    {
        $url_parts = @parse_url($link);

        if (empty($url_parts['host'])) {
            return false;
        }
        $host = $url_parts['host'];

        if (!empty($url_parts['path'])) {
            $documentpath = $url_parts['path'];
        } else {
            $documentpath = '/';
        }

        if (!empty($url_parts['query'])) {
            $documentpath .= '?' . $url_parts['query'];
        }

        if (!empty($url_parts['port'])) {
            $port = $url_parts['port'];
        } else {
            $port = '80';
        }

        $socket = @fsockopen($host, $port, $errno, $errstr, 30);

        if (!$socket) {
            return false;
        } else {
            fwrite($socket, "HEAD " . $documentpath . " HTTP/1.0\r\nHost: $host\r\n\r\n");
            $http_response = fgets($socket, 22);

            if (preg_match('/200 OK/', $http_response, $regs)) {
                fclose($socket);
                return true;
            } else {
                return false;
            }
        }
    }