1--TEST--
2mysqli_pconnect()
3--SKIPIF--
4<?php
5require_once('skipif.inc');
6require_once('skipifconnectfailure.inc');
7?>
8--FILE--
9<?php
10    require_once("connect.inc");
11
12    $host = 'p:' . $host;
13    if (!$link = my_mysqli_connect($host, $user, $passwd, $db, $port, $socket))
14        printf("[002] Cannot connect to the server using host=%s, user=%s, passwd=***, dbname=%s, port=%s, socket=%s\n",
15            $host, $user, $db, $port, $socket);
16
17    mysqli_close($link);
18
19    $num = 20;
20    $connections = array();
21    for ($i = 0; $i < $num; $i++) {
22        if (!$link = my_mysqli_connect($host, $user, $passwd, $db, $port, $socket))
23            printf("[003] Connect failed, [%d] %s\n", mysqli_connect_errno(), mysqli_connect_error());
24        $connections[] = $link;
25    }
26    while (count($connections)) {
27        do {
28            $index = mt_rand(0, $num);
29        } while (!isset($connections[$index]));
30        mysqli_close($connections[$index]);
31        unset($connections[$index]);
32    }
33
34
35    $connections = array();
36    $num = 20;
37    for ($i = 0; $i < $num; $i++) {
38        if (!$link = my_mysqli_connect($host, $user, $passwd, $db, $port, $socket))
39            printf("[004] Connect failed, [%d] %s\n", mysqli_connect_errno(), mysqli_connect_error());
40        $connections[] = $link;
41    }
42    $left = $num;
43
44    while (count($connections) && $left > 0) {
45        do {
46            $index = mt_rand(0, $num);
47        } while (!isset($connections[$index]) && $left > 0);
48        if (mt_rand(0, 1) > 0) {
49            $left--;
50            mysqli_close($connections[$index]);
51            unset($connections[$index]);
52        } else {
53            $left--;
54            if (!$connections[$index] = my_mysqli_connect($host, $user, $passwd, $db, $port, $socket))
55                printf("[004] Connect failed, [%d] %s\n", mysqli_connect_errno(), mysqli_connect_error());
56        }
57        flush();
58    }
59
60    while (count($connections)) {
61        do {
62            $index = mt_rand(0, $num);
63        } while (!isset($connections[$index]));
64        mysqli_close($connections[$index]);
65        unset($connections[$index]);
66    }
67
68    print "done!";
69?>
70--EXPECT--
71done!
72