Annotation of embedaddon/php/ext/mysql/tests/mysql_max_persistent.phpt, revision 1.1
1.1 ! misho 1: --TEST--
! 2: mysql_[p]connect() - max_links/max_persistent
! 3: --SKIPIF--
! 4: <?php
! 5: require_once('skipif.inc');
! 6: require_once('skipifconnectfailure.inc');
! 7: require_once('table.inc');
! 8:
! 9: mysql_query('DROP USER pcontest', $link);
! 10: if (!mysql_query('CREATE USER pcontest IDENTIFIED BY "pcontest"', $link)) {
! 11: printf("skip Cannot create second DB user [%d] %s", mysql_errno($link), mysql_error($link));
! 12: mysql_close($link);
! 13: die();
! 14: }
! 15:
! 16: // we might be able to specify the host using CURRENT_USER(), but...
! 17: if (!mysql_query(sprintf("GRANT SELECT ON TABLE %s.test TO pcontest@'%%'", $db), $link)) {
! 18: printf("skip Cannot GRANT SELECT to second DB user [%d] %s", mysql_errno($link), mysql_error($link));
! 19: mysql_query('REVOKE ALL PRIVILEGES, GRANT OPTION FROM pcontest', $link);
! 20: mysql_query('DROP USER pcontest', $link);
! 21: mysql_close($link);
! 22: die();
! 23: }
! 24: mysql_close($link);
! 25: ?>
! 26: --INI--
! 27: mysql.max_links=2
! 28: mysql.allow_persistent=1
! 29: mysql.max_persistent=1
! 30: --FILE--
! 31: <?php
! 32: require_once('connect.inc');
! 33:
! 34: function my_connect($offset, $host, $user, $passwd, $db, $port, $socket) {
! 35: if ($socket)
! 36: $host = sprintf("%s:%s", $host, $socket);
! 37: else if ($port)
! 38: $host = sprintf("%s:%s", $host, $port);
! 39:
! 40:
! 41: $link = mysql_pconnect($host, $user, $passwd);
! 42: if (!$link) {
! 43: printf("[%03d] Cannot connect using host '%s', user '%s', password '****', [%d] %s\n",
! 44: $offset, $host, $user, $passwd,
! 45: mysql_errno(), mysql_error());
! 46: return false;
! 47: }
! 48:
! 49: if (!mysql_select_db($db, $link))
! 50: return false;
! 51:
! 52: return $link;
! 53: }
! 54:
! 55: $links = array();
! 56:
! 57: // try to open 2 links
! 58: $links[0] = my_connect(10, $host, $user, $passwd, $db, $port, $socket);
! 59: $links[1] = my_connect(20, $host, 'pcontest', 'pcontest', $db, $port, $socket);
! 60: if (false !== $links[1])
! 61: printf("[030] Last connection should not have been allowed!\n");
! 62:
! 63: // free some links but let index 1 remain
! 64: unset($links[1]);
! 65: mysql_close($links[0]);
! 66: unset($links[0]);
! 67:
! 68: // should be allowed -> only open connection
! 69: $links[0] = my_connect(40, $host, $user, $passwd, $db, $port, $socket);
! 70: var_dump($links);
! 71:
! 72: mysql_query('REVOKE ALL PRIVILEGES, GRANT OPTION FROM pcontest', $links[0]);
! 73: mysql_query('DROP USER pcontest', $links[0]);
! 74:
! 75: mysql_close($links[0]);
! 76: print "done!\n";
! 77: ?>
! 78: --CLEAN--
! 79: <?php
! 80: // connect + select_db
! 81: require_once("connect.inc");
! 82: if (!$link = my_mysql_connect($host, $user, $passwd, $db, $port, $socket)) {
! 83: printf("[c001] Cannot connect to the server using host=%s/%s, user=%s, passwd=***, dbname=%s, port=%s, socket=%s\n",
! 84: $host, $myhost, $user, $db, $port, $socket);
! 85: }
! 86:
! 87: @mysql_query('REVOKE ALL PRIVILEGES, GRANT OPTION FROM pcontest', $link);
! 88: @mysql_query('DROP USER pcontest', $link);
! 89:
! 90: mysql_close($link);
! 91: ?>
! 92: --EXPECTF--
! 93: Warning: mysql_pconnect(): Too many open persistent links (1) in %s on line %d
! 94: [020] Cannot connect using host '%s', user '%s', password '****', [0] 0
! 95: array(1) {
! 96: [0]=>
! 97: resource(%d) of type (mysql link persistent)
! 98: }
! 99: done!
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>