1--TEST--
2mysql_[p]connect() - max_links/max_persistent
3--SKIPIF--
4<?php
5require_once('skipif.inc');
6require_once('skipifconnectfailure.inc');
7?>
8--INI--
9mysql.max_links=2
10--FILE--
11<?php
12require_once('connect.inc');
13
14function my_connect($offset, $host, $user, $passwd, $db, $port, $socket) {
15	if ($socket)
16		$host = sprintf("%s:%s", $host, $socket);
17	else if ($port)
18		$host = sprintf("%s:%s", $host, $port);
19
20	$link = mysql_connect($host, $user, $passwd, true);
21
22	if (!$link) {
23		printf("[%03d] Cannot connect using host '%s', user '%s', password '****', [%d] %s\n",
24			$offset, $host, $user, $passwd,
25			mysql_errno(), mysql_error());
26		return false;
27	}
28
29	return $link;
30}
31
32$links = array();
33
34// try to open 3 links
35$links[0] = my_connect(10, $host, $user, $passwd, $db, $port, $socket);
36$links[1] = my_connect(20, $host, $user, $passwd, $db, $port, $socket);
37$links[2] = my_connect(30, $host, $user, $passwd, $db, $port, $socket);
38if (false !== $links[2])
39	printf("[040] Last connection should not have been allowed!\n");
40
41// free some links but let index 1 remain
42unset($links[2]);
43mysql_close($links[0]);
44unset($links[0]);
45
46// should be allowed -> second open connection
47$links[0] = my_connect(50, $host, $user, $passwd, $db, $port, $socket);
48$links[2] = my_connect(60, $host, $user, $passwd, $db, $port, $socket);
49ksort($links);
50var_dump($links);
51
52mysql_close($links[0]);
53mysql_close($links[1]);
54print "done!\n";
55?>
56--EXPECTF--
57Warning: mysql_connect(): Too many open links (2) in %s on line %s
58[030] Cannot connect using host '%s', user '%s', password '****', [0] 0
59
60Warning: mysql_connect(): Too many open links (2) in %s on line %s
61[060] Cannot connect using host '%s', user '%s', password '****', [0] 0
62array(3) {
63  [0]=>
64  resource(%d) of type (mysql link)
65  [1]=>
66  resource(%d) of type (mysql link)
67  [2]=>
68  bool(false)
69}
70done!