Annotation of embedaddon/php/ext/mysql/tests/mysql_max_links.phpt, revision 1.1

1.1     ! misho       1: --TEST--
        !             2: mysql_[p]connect() - max_links/max_persistent
        !             3: --SKIPIF--
        !             4: <?php
        !             5: require_once('skipif.inc');
        !             6: require_once('skipifconnectfailure.inc');
        !             7: ?>
        !             8: --INI--
        !             9: mysql.max_links=2
        !            10: --FILE--
        !            11: <?php
        !            12: require_once('connect.inc');
        !            13: 
        !            14: function my_connect($offset, $host, $user, $passwd, $db, $port, $socket) {
        !            15:        if ($socket)
        !            16:                $host = sprintf("%s:%s", $host, $socket);
        !            17:        else if ($port)
        !            18:                $host = sprintf("%s:%s", $host, $port);
        !            19: 
        !            20:        $link = mysql_connect($host, $user, $passwd, true);
        !            21: 
        !            22:        if (!$link) {
        !            23:                printf("[%03d] Cannot connect using host '%s', user '%s', password '****', [%d] %s\n",
        !            24:                        $offset, $host, $user, $passwd,
        !            25:                        mysql_errno(), mysql_error());
        !            26:                return false;
        !            27:        }
        !            28: 
        !            29:        return $link;
        !            30: }
        !            31: 
        !            32: $links = array();
        !            33: 
        !            34: // try to open 3 links
        !            35: $links[0] = my_connect(10, $host, $user, $passwd, $db, $port, $socket);
        !            36: $links[1] = my_connect(20, $host, $user, $passwd, $db, $port, $socket);
        !            37: $links[2] = my_connect(30, $host, $user, $passwd, $db, $port, $socket);
        !            38: if (false !== $links[2])
        !            39:        printf("[040] Last connection should not have been allowed!\n");
        !            40: 
        !            41: // free some links but let index 1 remain
        !            42: unset($links[2]);
        !            43: mysql_close($links[0]);
        !            44: unset($links[0]);
        !            45: 
        !            46: // should be allowed -> second open connection
        !            47: $links[0] = my_connect(50, $host, $user, $passwd, $db, $port, $socket);
        !            48: $links[2] = my_connect(60, $host, $user, $passwd, $db, $port, $socket);
        !            49: ksort($links);
        !            50: var_dump($links);
        !            51: 
        !            52: mysql_close($links[0]);
        !            53: mysql_close($links[1]);
        !            54: print "done!\n";
        !            55: ?>
        !            56: --EXPECTF--
        !            57: Warning: mysql_connect(): Too many open links (2) in %s on line %s
        !            58: [030] Cannot connect using host '%s', user '%s', password '****', [0] 0
        !            59: 
        !            60: Warning: mysql_connect(): Too many open links (2) in %s on line %s
        !            61: [060] Cannot connect using host '%s', user '%s', password '****', [0] 0
        !            62: array(3) {
        !            63:   [0]=>
        !            64:   resource(%d) of type (mysql link)
        !            65:   [1]=>
        !            66:   resource(%d) of type (mysql link)
        !            67:   [2]=>
        !            68:   bool(false)
        !            69: }
        !            70: done!

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>