summaryrefslogtreecommitdiff
path: root/ext/mysqli/tests/mysqli_pconn_kill.phpt
blob: f8d8d7e8bd501091406932a9fd3c5f8e444b8e89 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
--TEST--
Killing a persistent connection.
--SKIPIF--
<?php
require_once('skipif.inc');
require_once('skipifemb.inc');
require_once('skipifconnectfailure.inc');
require_once("connect.inc");
?>
--INI--
mysqli.allow_persistent=1
mysqli.max_persistent=2
--FILE--
<?php
	require_once("connect.inc");
	require_once("table.inc");

	$host = 'p:' . $host;
	if (!$plink = my_mysqli_connect($host, $user, $passwd, $db, $port, $socket))
		printf("[001] Cannot connect to the server using host=%s, user=%s, passwd=***, dbname=%s, port=%s, socket=%s\n",
			$host, $user, $db, $port, $socket);

	// get the thread ids of the two connections...
	$thread_id = mysqli_thread_id($link);
	$pthread_id = mysqli_thread_id($plink);

	if (!$res = mysqli_query($link, 'SHOW FULL PROCESSLIST'))
		printf("[002] Cannot get processlist, [%d] %s\n", mysqli_errno($link), mysqli_error($link));

	$running_threads = array();
	while ($row = mysqli_fetch_assoc($res))
		$running_threads[$row['Id']] = $row;
	mysqli_free_result($res);

	if (count($running_threads) < 2)
		printf("[003] Processlist is too short, [%d] %s\n", mysqli_errno($link), mysqli_error($link));

	if (!isset($running_threads[$thread_id]))
		printf("[004] Cannot find thread id of the regular link, [%d] %s\n", mysqli_errno($link), mysqli_error($link));

	if (!isset($running_threads[$pthread_id]))
		printf("[005] Cannot find thread id of the persistent link, [%d] %s\n", mysqli_errno($link), mysqli_error($link));

	// Kill the persistent connection - don't use mysqli_kill, mysqlnd will catch that...
	if (!mysqli_query($link, sprintf('KILL %d', $pthread_id)))
		printf("[006] Cannot kill persistent connection, [%d] %s\n", mysqli_errno($link), mysqli_error($link));
	mysqli_close($plink);
	// Give the server think-time to kill the pthread
	sleep(1);

	if (!$res = mysqli_query($link, 'SHOW FULL PROCESSLIST'))
		printf("[007] Cannot get processlist, [%d] %s\n", mysqli_errno($link), mysqli_error($link));

	$running_threads2 = array();
	while ($row = mysqli_fetch_assoc($res))
		$running_threads2[$row['Id']] = $row;
	mysqli_free_result($res);

	if (isset($running_threads2[$pthread_id]))
		printf("[008] Thread of the persistent connection should have been gone, [%d] %s\n", mysqli_errno($link), mysqli_error($link));
	if (!isset($running_threads2[$thread_id]))
		printf("[009] Thread of the regular connection should be still there, [%d] %s\n", mysqli_errno($link), mysqli_error($link));

	// On PHP side this should do nothing. PHP should not try to close the connection or something.
	@mysqli_close($plink);

	if (!$plink = @my_mysqli_connect($host, $user, $passwd, $db, $port, $socket))
		printf("[011] Cannot connect to the server using host=%s, user=%s, passwd=***, dbname=%s, port=%s, socket=%s\n",
			$host, $user, $db, $port, $socket);
	if (!$res3 = @mysqli_query($plink, 'SELECT id FROM test ORDER BY id LIMIT 1')) {
		printf("[012] New persistent connection cannot execute queries, [%d] %s\n", @mysqli_errno($plink), @mysqli_error($plink));
	}

	@mysqli_free_result($res3);
	@mysqli_close($plink);
	mysqli_close($link);

	// remove the "p:<host>" from the host variable
	$host = substr($host, 2);
	if (!$link = my_mysqli_connect($host, $user, $passwd, $db, $port, $socket))
		printf("[013] Cannot connect to the server using host=%s, user=%s, passwd=***, dbname=%s, port=%s, socket=%s\n",
			$host, $user, $db, $port, $socket);
	if (!$res4 = mysqli_query($link, 'SELECT id FROM test ORDER BY id LIMIT 1'))
		printf("[014] New regular connection cannot execute queries, [%d] %s\n", mysqli_errno($link), mysqli_error($link));

	mysqli_free_result($res4);
	mysqli_close($link);
	print "done!";
?>
--CLEAN--
<?php
	require_once("clean_table.inc");
?>
--EXPECTF--
done!