Annotation of embedaddon/php/ext/mysqli/tests/mysqli_pconn_kill.phpt, revision 1.1
1.1 ! misho 1: --TEST--
! 2: Killing a persistent connection.
! 3: --SKIPIF--
! 4: <?php
! 5: require_once('skipif.inc');
! 6: require_once('skipifemb.inc');
! 7: require_once('skipifconnectfailure.inc');
! 8: require_once("connect.inc");
! 9: ?>
! 10: --INI--
! 11: mysqli.allow_persistent=1
! 12: mysqli.max_persistent=2
! 13: --FILE--
! 14: <?php
! 15: require_once("connect.inc");
! 16: require_once("table.inc");
! 17:
! 18: $host = 'p:' . $host;
! 19: if (!$plink = my_mysqli_connect($host, $user, $passwd, $db, $port, $socket))
! 20: printf("[001] Cannot connect to the server using host=%s, user=%s, passwd=***, dbname=%s, port=%s, socket=%s\n",
! 21: $host, $user, $db, $port, $socket);
! 22:
! 23: // get the thread ids of the two connections...
! 24: $thread_id = mysqli_thread_id($link);
! 25: $pthread_id = mysqli_thread_id($plink);
! 26:
! 27: if (!$res = mysqli_query($link, 'SHOW FULL PROCESSLIST'))
! 28: printf("[002] Cannot get processlist, [%d] %s\n", mysqli_errno($link), mysqli_error($link));
! 29:
! 30: $running_threads = array();
! 31: while ($row = mysqli_fetch_assoc($res))
! 32: $running_threads[$row['Id']] = $row;
! 33: mysqli_free_result($res);
! 34:
! 35: if (count($running_threads) < 2)
! 36: printf("[003] Processlist is too short, [%d] %s\n", mysqli_errno($link), mysqli_error($link));
! 37:
! 38: if (!isset($running_threads[$thread_id]))
! 39: printf("[004] Cannot find thread id of the regular link, [%d] %s\n", mysqli_errno($link), mysqli_error($link));
! 40:
! 41: if (!isset($running_threads[$pthread_id]))
! 42: printf("[005] Cannot find thread id of the persistent link, [%d] %s\n", mysqli_errno($link), mysqli_error($link));
! 43:
! 44: // Kill the persistent connection - don't use mysqli_kill, mysqlnd will catch that...
! 45: if (!mysqli_query($link, sprintf('KILL %d', $pthread_id)))
! 46: printf("[006] Cannot kill persistent connection, [%d] %s\n", mysqli_errno($link), mysqli_error($link));
! 47: mysqli_close($plink);
! 48: // Give the server think-time to kill the pthread
! 49: sleep(1);
! 50:
! 51: if (!$res = mysqli_query($link, 'SHOW FULL PROCESSLIST'))
! 52: printf("[007] Cannot get processlist, [%d] %s\n", mysqli_errno($link), mysqli_error($link));
! 53:
! 54: $running_threads2 = array();
! 55: while ($row = mysqli_fetch_assoc($res))
! 56: $running_threads2[$row['Id']] = $row;
! 57: mysqli_free_result($res);
! 58:
! 59: if (isset($running_threads2[$pthread_id]))
! 60: printf("[008] Thread of the persistent connection should have been gone, [%d] %s\n", mysqli_errno($link), mysqli_error($link));
! 61: if (!isset($running_threads2[$thread_id]))
! 62: printf("[009] Thread of the regular connection should be still there, [%d] %s\n", mysqli_errno($link), mysqli_error($link));
! 63:
! 64: // On PHP side this should do nothing. PHP should not try to close the connection or something.
! 65: @mysqli_close($plink);
! 66:
! 67: if (!$plink = @my_mysqli_connect($host, $user, $passwd, $db, $port, $socket))
! 68: printf("[011] Cannot connect to the server using host=%s, user=%s, passwd=***, dbname=%s, port=%s, socket=%s\n",
! 69: $host, $user, $db, $port, $socket);
! 70: if (!$res3 = @mysqli_query($plink, 'SELECT id FROM test ORDER BY id LIMIT 1')) {
! 71: printf("[012] New persistent connection cannot execute queries, [%d] %s\n", @mysqli_errno($plink), @mysqli_error($plink));
! 72: }
! 73:
! 74: @mysqli_free_result($res3);
! 75: @mysqli_close($plink);
! 76: mysqli_close($link);
! 77:
! 78: // remove the "p:<host>" from the host variable
! 79: $host = substr($host, 2);
! 80: if (!$link = my_mysqli_connect($host, $user, $passwd, $db, $port, $socket))
! 81: printf("[013] Cannot connect to the server using host=%s, user=%s, passwd=***, dbname=%s, port=%s, socket=%s\n",
! 82: $host, $user, $db, $port, $socket);
! 83: if (!$res4 = mysqli_query($link, 'SELECT id FROM test ORDER BY id LIMIT 1'))
! 84: printf("[014] New regular connection cannot execute queries, [%d] %s\n", mysqli_errno($link), mysqli_error($link));
! 85:
! 86: mysqli_free_result($res4);
! 87: mysqli_close($link);
! 88: print "done!";
! 89: ?>
! 90: --CLEAN--
! 91: <?php
! 92: require_once("clean_table.inc");
! 93: ?>
! 94: --EXPECTF--
! 95: done!
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>