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

1.1     ! misho       1: --TEST--
        !             2: Bug #5547 (mysql_pconnect leaks file descriptors on reconnect)
        !             3: --SKIPIF--
        !             4: <?php
        !             5: require_once('skipif.inc');
        !             6: require_once('skipifconnectfailure.inc');
        !             7: if (defined('PHP_WINDOWS_VERSION_MAJOR')) {
        !             8:        die("skip Test doesn't work on Windows");
        !             9: }
        !            10: 
        !            11: if (!($output = @exec("lsof -np " . getmypid())))
        !            12:        die("skip Test can't find command line tool lsof");
        !            13: ?>
        !            14: --INI--
        !            15: mysql.max_persistent=30
        !            16: mysql.allow_persistent=1
        !            17: --FILE--
        !            18: <?php
        !            19:        include "connect.inc";
        !            20: 
        !            21:        $tmp    = NULL;
        !            22:        $link   = NULL;
        !            23: 
        !            24:        if ($socket)
        !            25:         $host = sprintf("%s:%s", $host, $socket);
        !            26:     else if ($port)
        !            27:         $host = sprintf("%s:%s", $host, $port);
        !            28: 
        !            29:        function connect($host, $user, $passwd) {
        !            30:                $conn = mysql_pconnect($host, $user, $passwd);
        !            31: 
        !            32:                if (!$conn)
        !            33:                        die(sprintf("[001] %s\n", mysql_error()));
        !            34: 
        !            35:                if (!mysql_query("set wait_timeout=1", $conn))
        !            36:                        printf("[002] [%d] %s\n", mysql_errno($conn), mysql_error($conn));
        !            37: 
        !            38:                return $conn;
        !            39:        }       
        !            40: 
        !            41:        $conn = connect($host, $user, $passwd);
        !            42:        $opened_files = -1;
        !            43: 
        !            44:        for ($i = 0; $i < 4; $i++) {
        !            45:                /* wait while mysql closes connection */
        !            46:                sleep(3);
        !            47: 
        !            48:                if (!mysql_ping($conn)) {
        !            49:                        printf("[003] reconnect %d\n", $i);
        !            50:                        $conn = connect($host, $user, $passwd);  
        !            51:                }
        !            52: 
        !            53:                $r = mysql_query('select 1', $conn);
        !            54:                if (!$r)
        !            55:                        printf("[004] [%d] %s\n", mysql_errno($conn), mysql_error($conn));
        !            56: 
        !            57: 
        !            58:                if ($opened_files == -1) {
        !            59:                        $opened_files = trim(exec("lsof -np " . getmypid() . " | wc -l"));
        !            60:                        printf("[005] Setting openened files...\n");
        !            61:                } else if (($tmp = trim(exec("lsof -np " . getmypid() . " | wc -l"))) != $opened_files) {
        !            62:                        printf("[006] [%d] different number of opened_files : expected %d, got %d", $i, $opened_files, $tmp);
        !            63:                } else {
        !            64:                        printf("[007] Opened files as expected\n");
        !            65:                }
        !            66:        }
        !            67: 
        !            68:        print "done!";
        !            69: ?>
        !            70: --EXPECTF--
        !            71: [003] reconnect 0
        !            72: [005] Setting openened files...
        !            73: [003] reconnect 1
        !            74: [007] Opened files as expected
        !            75: [003] reconnect 2
        !            76: [007] Opened files as expected
        !            77: [003] reconnect 3
        !            78: [007] Opened files as expected
        !            79: done!

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