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

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:        if (!($plink = @mysql_pconnect($myhost, $user, $passwd)))
                     68:                printf("[009] Cannot create new persistent connection, [%d] %s\n", mysql_errno(), mysql_error());
                     69:        mysql_select_db($db, $plink);
                     70: 
                     71:        if (!($res = mysql_query("SELECT 1", $plink)))
                     72:                printf("[010] Cannot run query on new persistent connection, [%d] %s\n", @mysql_errno($plink), @mysql_error($plink));
                     73:        mysql_free_result($res);
                     74: 
                     75:        var_dump(mysql_ping($plink));
                     76: 
                     77:        if (!($res = mysql_query("SELECT 1", $plink)))
                     78:                printf("[011] Cannot run query on new persistent connection, [%d] %s\n", @mysql_errno($plink), @mysql_error($plink));
                     79:        mysql_free_result($res);
                     80: 
                     81:        if (!($link2 = mysql_connect($myhost, $user, $passwd, true)))
                     82:                printf("[012] Cannot connect to the server using host=%s/%s, user=%s, passwd=***, dbname=%s, port=%s, socket=%s\n",
                     83:                        $host, $myhost, $user, $db, $port, $socket);
                     84:        mysql_select_db($db, $link2);
                     85:        if (!mysql_query(sprintf("KILL %d", $thread_id), $link2))
                     86:                printf("[013] Cannot kill regular connection thread, [%d] %s\n", mysql_errno($link2), mysql_error($link2));
                     87: 
                     88:        if (!($link = mysql_connect($myhost, $user, $passwd, true)))
                     89:                printf("[014] Cannot connect to the server using host=%s/%s, user=%s, passwd=***, dbname=%s, port=%s, socket=%s\n",
                     90:                        $host, $myhost, $user, $db, $port, $socket);
                     91:        mysql_select_db($db, $link);
                     92:        if (!($res = mysql_query("SELECT * FROM test", $link)))
                     93:                printf("[015] Cannot run query on new regular connection, [%d] %s\n", @mysql_errno($link), @mysql_error($link));
                     94: 
                     95:        if (!($res = mysql_query("SELECT * FROM test", $link2)))
                     96:                printf("[016] Cannot run query on other regular connection, [%d] %s\n", @mysql_errno($link2), @mysql_error($link2));
                     97: 
                     98:        mysql_free_result($res);
                     99:        mysql_close($plink);
                    100:        mysql_close($link);
                    101:        mysql_close($link2);
                    102:        print "done!";
                    103: ?>
                    104: --CLEAN--
                    105: <?php
                    106: require_once("clean_table.inc");
                    107: ?>
                    108: --EXPECTF--
                    109: bool(true)
                    110: done!

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