summaryrefslogtreecommitdiff
path: root/ext/mysqli/tests/mysqli_pconnect.phpt
blob: faa78fa9c288ed08fee8e6327062257dc52dc5ca (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
--TEST--
mysqli_pconnect()
--SKIPIF--
<?php
require_once('skipif.inc');
require_once('skipifemb.inc');
require_once('skipifconnectfailure.inc');
?>
--FILE--
<?php
	require_once("connect.inc");

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

	mysqli_close($link);

	$num = 20;
	$connections = array();
	for ($i = 0; $i < $num; $i++) {
		if (!$link = my_mysqli_connect($host, $user, $passwd, $db, $port, $socket))
			printf("[003] Connect failed, [%d] %s\n", mysqli_connect_errno(), mysqli_connect_error());
		$connections[] = $link;
	}
	while (count($connections)) {
		do {
			$index = mt_rand(0, $num);
		} while (!isset($connections[$index]));
		mysqli_close($connections[$index]);
		unset($connections[$index]);
	}


	$connections = array();
	$num = 20;
	for ($i = 0; $i < $num; $i++) {
		if (!$link = my_mysqli_connect($host, $user, $passwd, $db, $port, $socket))
			printf("[004] Connect failed, [%d] %s\n", mysqli_connect_errno(), mysqli_connect_error());
		$connections[] = $link;
	}
	$left = $num;

	while (count($connections) && $left > 0) {
		do {
			$index = mt_rand(0, $num);
		} while (!isset($connections[$index]) && $left > 0);
		if (mt_rand(0, 1) > 0) {
			$left--;
			mysqli_close($connections[$index]);
			unset($connections[$index]);
		} else {
			$left--;
			if (!$connections[$index] = my_mysqli_connect($host, $user, $passwd, $db, $port, $socket))
				printf("[004] Connect failed, [%d] %s\n", mysqli_connect_errno(), mysqli_connect_error());
		}
		flush();
	}

	while (count($connections)) {
		do {
			$index = mt_rand(0, $num);
		} while (!isset($connections[$index]));
		mysqli_close($connections[$index]);
		unset($connections[$index]);
	}

	print "done!";
?>
--EXPECTF--
done!