mysql_max_persistent.phpt 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  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. mysql_query('DROP USER pcontest', $link);
  9. if (!mysql_query('CREATE USER pcontest IDENTIFIED BY "pcontest"', $link)) {
  10. printf("skip Cannot create second DB user [%d] %s", mysql_errno($link), mysql_error($link));
  11. mysql_close($link);
  12. die();
  13. }
  14. // we might be able to specify the host using CURRENT_USER(), but...
  15. if (!mysql_query(sprintf("GRANT SELECT ON TABLE %s.test TO pcontest@'%%'", $db), $link)) {
  16. printf("skip Cannot GRANT SELECT to second DB user [%d] %s", mysql_errno($link), mysql_error($link));
  17. mysql_query('REVOKE ALL PRIVILEGES, GRANT OPTION FROM pcontest', $link);
  18. mysql_query('DROP USER pcontest', $link);
  19. mysql_close($link);
  20. die();
  21. }
  22. mysql_close($link);
  23. ?>
  24. --INI--
  25. mysql.max_links=2
  26. mysql.allow_persistent=1
  27. mysql.max_persistent=1
  28. --FILE--
  29. <?php
  30. require_once('connect.inc');
  31. function my_connect($offset, $host, $user, $passwd, $db, $port, $socket) {
  32. if ($socket)
  33. $host = sprintf("%s:%s", $host, $socket);
  34. else if ($port)
  35. $host = sprintf("%s:%s", $host, $port);
  36. $link = mysql_pconnect($host, $user, $passwd);
  37. if (!$link) {
  38. printf("[%03d] Cannot connect using host '%s', user '%s', password '****', [%d] %s\n",
  39. $offset, $host, $user, $passwd,
  40. mysql_errno(), mysql_error());
  41. return false;
  42. }
  43. if (!mysql_select_db($db, $link))
  44. return false;
  45. return $link;
  46. }
  47. $links = array();
  48. // try to open 2 links
  49. $links[0] = my_connect(10, $host, $user, $passwd, $db, $port, $socket);
  50. $links[1] = my_connect(20, $host, 'pcontest', 'pcontest', $db, $port, $socket);
  51. if (false !== $links[1])
  52. printf("[030] Last connection should not have been allowed!\n");
  53. // free some links but let index 1 remain
  54. unset($links[1]);
  55. mysql_close($links[0]);
  56. unset($links[0]);
  57. // should be allowed -> only open connection
  58. $links[0] = my_connect(40, $host, $user, $passwd, $db, $port, $socket);
  59. var_dump($links);
  60. mysql_query('REVOKE ALL PRIVILEGES, GRANT OPTION FROM pcontest', $links[0]);
  61. mysql_query('DROP USER pcontest', $links[0]);
  62. mysql_close($links[0]);
  63. print "done!\n";
  64. ?>
  65. --CLEAN--
  66. <?php
  67. // connect + select_db
  68. require_once("connect.inc");
  69. if (!$link = my_mysql_connect($host, $user, $passwd, $db, $port, $socket)) {
  70. printf("[c001] Cannot connect to the server using host=%s/%s, user=%s, passwd=***, dbname=%s, port=%s, socket=%s\n",
  71. $host, $myhost, $user, $db, $port, $socket);
  72. }
  73. @mysql_query('REVOKE ALL PRIVILEGES, GRANT OPTION FROM pcontest', $link);
  74. @mysql_query('DROP USER pcontest', $link);
  75. mysql_close($link);
  76. ?>
  77. --EXPECTF--
  78. Deprecated: mysql_pconnect(): The mysql extension is deprecated and will be removed in the future: use mysqli or PDO instead in %s on line %d
  79. Deprecated: mysql_pconnect(): The mysql extension is deprecated and will be removed in the future: use mysqli or PDO instead in %s on line %d
  80. Warning: mysql_pconnect(): Too many open persistent links (1) in %s on line %d
  81. [020] Cannot connect using host '%s', user '%s', password '****', [0] 0
  82. Deprecated: mysql_pconnect(): The mysql extension is deprecated and will be removed in the future: use mysqli or PDO instead in %s on line %d
  83. array(1) {
  84. [0]=>
  85. resource(%d) of type (mysql link persistent)
  86. }
  87. done!