diff options
author | Lorry Tar Creator <lorry-tar-importer@baserock.org> | 2013-03-14 05:42:27 +0000 |
---|---|---|
committer | <> | 2013-04-03 16:25:08 +0000 |
commit | c4dd7a1a684490673e25aaf4fabec5df138854c4 (patch) | |
tree | 4d57c44caae4480efff02b90b9be86f44bf25409 /ext/mysql/tests/mysql_max_links.phpt | |
download | php2-master.tar.gz |
Imported from /home/lorry/working-area/delta_php2/php-5.4.13.tar.bz2.HEADphp-5.4.13master
Diffstat (limited to 'ext/mysql/tests/mysql_max_links.phpt')
-rw-r--r-- | ext/mysql/tests/mysql_max_links.phpt | 70 |
1 files changed, 70 insertions, 0 deletions
diff --git a/ext/mysql/tests/mysql_max_links.phpt b/ext/mysql/tests/mysql_max_links.phpt new file mode 100644 index 0000000..52ecd0a --- /dev/null +++ b/ext/mysql/tests/mysql_max_links.phpt @@ -0,0 +1,70 @@ +--TEST-- +mysql_[p]connect() - max_links/max_persistent +--SKIPIF-- +<?php +require_once('skipif.inc'); +require_once('skipifconnectfailure.inc'); +?> +--INI-- +mysql.max_links=2 +--FILE-- +<?php +require_once('connect.inc'); + +function my_connect($offset, $host, $user, $passwd, $db, $port, $socket) { + if ($socket) + $host = sprintf("%s:%s", $host, $socket); + else if ($port) + $host = sprintf("%s:%s", $host, $port); + + $link = mysql_connect($host, $user, $passwd, true); + + if (!$link) { + printf("[%03d] Cannot connect using host '%s', user '%s', password '****', [%d] %s\n", + $offset, $host, $user, $passwd, + mysql_errno(), mysql_error()); + return false; + } + + return $link; +} + +$links = array(); + +// try to open 3 links +$links[0] = my_connect(10, $host, $user, $passwd, $db, $port, $socket); +$links[1] = my_connect(20, $host, $user, $passwd, $db, $port, $socket); +$links[2] = my_connect(30, $host, $user, $passwd, $db, $port, $socket); +if (false !== $links[2]) + printf("[040] Last connection should not have been allowed!\n"); + +// free some links but let index 1 remain +unset($links[2]); +mysql_close($links[0]); +unset($links[0]); + +// should be allowed -> second open connection +$links[0] = my_connect(50, $host, $user, $passwd, $db, $port, $socket); +$links[2] = my_connect(60, $host, $user, $passwd, $db, $port, $socket); +ksort($links); +var_dump($links); + +mysql_close($links[0]); +mysql_close($links[1]); +print "done!\n"; +?> +--EXPECTF-- +Warning: mysql_connect(): Too many open links (2) in %s on line %s +[030] Cannot connect using host '%s', user '%s', password '****', [0] 0 + +Warning: mysql_connect(): Too many open links (2) in %s on line %s +[060] Cannot connect using host '%s', user '%s', password '****', [0] 0 +array(3) { + [0]=> + resource(%d) of type (mysql link) + [1]=> + resource(%d) of type (mysql link) + [2]=> + bool(false) +} +done!
\ No newline at end of file |