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

1.1     ! misho       1: --TEST--
        !             2: mysql_pconnect() - killing persitent connection
        !             3: --SKIPIF--
        !             4: <?php
        !             5: require_once('skipif.inc');
        !             6: require_once('skipifconnectfailure.inc');
        !             7: ?>
        !             8: --INI--
        !             9: mysql.allow_persistent=1
        !            10: mysql.max_persistent=2
        !            11: --FILE--
        !            12: <?php
        !            13:        include "connect.inc";
        !            14:        include "table.inc";
        !            15: 
        !            16:        if ($socket)
        !            17:                $myhost = sprintf("%s:%s", $host, $socket);
        !            18:        else if ($port)
        !            19:                $myhost = sprintf("%s:%s", $host, $port);
        !            20:        else
        !            21:                $myhost = $host;
        !            22: 
        !            23:        if (!($plink = mysql_pconnect($myhost, $user, $passwd)))
        !            24:                printf("[001] Cannot connect to the server using host=%s/%s, user=%s, passwd=***, dbname=%s, port=%s, socket=%s\n",
        !            25:                        $host, $myhost, $user, $db, $port, $socket);
        !            26:        mysql_select_db($db, $plink);
        !            27: 
        !            28:        $pthread_id = mysql_thread_id($plink);
        !            29:        $thread_id = mysql_thread_id($link);
        !            30: 
        !            31:        if (!($res = mysql_query("SHOW FULL PROCESSLIST", $link)))
        !            32:                printf("[002] Cannot get processlist, [%d] %s\n", mysql_errno($link), mysql_error($link));
        !            33: 
        !            34:        $processlist = array();
        !            35:        while ($row = mysql_fetch_assoc($res))
        !            36:                $processlist[$row['Id']] = $row;
        !            37:        mysql_free_result($res);
        !            38: 
        !            39:        if (!isset($processlist[$thread_id]))
        !            40:                printf("[003] Cannot find regular connection thread in process list, [%d] %s\n", mysql_errno($link), mysql_error($link));
        !            41:        if (!isset($processlist[$pthread_id]))
        !            42:                printf("[004] Cannot find persistent connection thread in process list, [%d] %s\n", mysql_errno($link), mysql_error($link));
        !            43: 
        !            44:        if (!mysql_query(sprintf("KILL %d", $pthread_id), $link))
        !            45:                printf("[005] Cannot kill persistent connection thread, [%d] %s\n", mysql_errno($link), mysql_error($link));
        !            46: 
        !            47:        while (1) {
        !            48:                if (!($res = mysql_query("SHOW FULL PROCESSLIST", $link)))
        !            49:                        printf("[006] Cannot get processlist, [%d] %s\n", mysql_errno($link), mysql_error($link));
        !            50: 
        !            51:                $processlist2 = array();
        !            52:                while ($row = mysql_fetch_assoc($res))
        !            53:                        $processlist2[$row['Id']] = $row;
        !            54:                mysql_free_result($res);
        !            55:                if (isset($processlist2[$pthread_id])) {
        !            56:                        sleep(1);
        !            57:                } else {
        !            58:                        break;
        !            59:                }
        !            60:        }
        !            61: 
        !            62:        if (!isset($processlist2[$thread_id]))
        !            63:                printf("[007] Cannot find regular connection thread in process list, [%d] %s\n", mysql_errno($link), mysql_error($link));
        !            64: 
        !            65:        mysql_close($plink);
        !            66: 
        !            67:        /* mysql_pconnect cound generate a warning when linked against mysqlnd 
        !            68:        PHP Warning:  mysql_pconnect(): MySQL server has gone away */  
        !            69:        if (!($plink = @mysql_pconnect($myhost, $user, $passwd)))
        !            70:                printf("[009] Cannot create new persistent connection, [%d] %s\n", mysql_errno(), mysql_error());
        !            71:        mysql_select_db($db, $plink);
        !            72: 
        !            73:        if (!($res = mysql_query("SELECT 1", $plink)))
        !            74:                printf("[010] Cannot run query on new persistent connection, [%d] %s\n", @mysql_errno($plink), @mysql_error($plink));
        !            75:        mysql_free_result($res);
        !            76: 
        !            77:        var_dump(mysql_ping($plink));
        !            78: 
        !            79:        if (!($res = mysql_query("SELECT 1", $plink)))
        !            80:                printf("[011] Cannot run query on new persistent connection, [%d] %s\n", @mysql_errno($plink), @mysql_error($plink));
        !            81:        mysql_free_result($res);
        !            82: 
        !            83:        if (!($link2 = mysql_connect($myhost, $user, $passwd, true)))
        !            84:                printf("[012] Cannot connect to the server using host=%s/%s, user=%s, passwd=***, dbname=%s, port=%s, socket=%s\n",
        !            85:                        $host, $myhost, $user, $db, $port, $socket);
        !            86:        mysql_select_db($db, $link2);
        !            87:        if (!mysql_query(sprintf("KILL %d", $thread_id), $link2))
        !            88:                printf("[013] Cannot kill regular connection thread, [%d] %s\n", mysql_errno($link2), mysql_error($link2));
        !            89: 
        !            90:        if (!($link = mysql_connect($myhost, $user, $passwd, true)))
        !            91:                printf("[014] Cannot connect to the server using host=%s/%s, user=%s, passwd=***, dbname=%s, port=%s, socket=%s\n",
        !            92:                        $host, $myhost, $user, $db, $port, $socket);
        !            93:        mysql_select_db($db, $link);
        !            94:        if (!($res = mysql_query("SELECT * FROM test", $link)))
        !            95:                printf("[015] Cannot run query on new regular connection, [%d] %s\n", @mysql_errno($link), @mysql_error($link));
        !            96: 
        !            97:        if (!($res = mysql_query("SELECT * FROM test", $link2)))
        !            98:                printf("[016] Cannot run query on other regular connection, [%d] %s\n", @mysql_errno($link2), @mysql_error($link2));
        !            99: 
        !           100:        mysql_free_result($res);
        !           101:        mysql_close($plink);
        !           102:        mysql_close($link);
        !           103:        mysql_close($link2);
        !           104:        print "done!";
        !           105: ?>
        !           106: --CLEAN--
        !           107: <?php
        !           108: require_once("clean_table.inc");
        !           109: ?>
        !           110: --EXPECTF--
        !           111: bool(true)
        !           112: done!

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