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-- 57Deprecated: mysql_connect(): The mysql extension is deprecated and will be removed in the future: use mysqli or PDO instead in %s on line %d 58 59Deprecated: mysql_connect(): The mysql extension is deprecated and will be removed in the future: use mysqli or PDO instead in %s on line %d 60 61Deprecated: mysql_connect(): The mysql extension is deprecated and will be removed in the future: use mysqli or PDO instead in %s on line %d 62 63Warning: mysql_connect(): Too many open links (2) in %s on line %s 64[030] Cannot connect using host '%s', user '%s', password '****', [0] 0 65 66Deprecated: mysql_connect(): The mysql extension is deprecated and will be removed in the future: use mysqli or PDO instead in %s on line %d 67 68Deprecated: mysql_connect(): The mysql extension is deprecated and will be removed in the future: use mysqli or PDO instead in %s on line %d 69 70Warning: mysql_connect(): Too many open links (2) in %s on line %s 71[060] Cannot connect using host '%s', user '%s', password '****', [0] 0 72array(3) { 73 [0]=> 74 resource(%d) of type (mysql link) 75 [1]=> 76 resource(%d) of type (mysql link) 77 [2]=> 78 bool(false) 79} 80done! 81