bug55473.phpt 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. --TEST--
  2. Bug #5547 (mysql_pconnect leaks file descriptors on reconnect)
  3. --SKIPIF--
  4. <?php
  5. require_once('skipif.inc');
  6. require_once('skipifconnectfailure.inc');
  7. if (defined('PHP_WINDOWS_VERSION_MAJOR')) {
  8. die("skip Test doesn't work on Windows");
  9. }
  10. if (!($output = @exec("lsof -np " . getmypid())))
  11. die("skip Test can't find command line tool lsof");
  12. ?>
  13. --INI--
  14. mysql.max_persistent=30
  15. mysql.allow_persistent=1
  16. --FILE--
  17. <?php
  18. include "connect.inc";
  19. $tmp = NULL;
  20. $link = NULL;
  21. if ($socket)
  22. $host = sprintf("%s:%s", $host, $socket);
  23. else if ($port)
  24. $host = sprintf("%s:%s", $host, $port);
  25. function connect($host, $user, $passwd) {
  26. $conn = mysql_pconnect($host, $user, $passwd);
  27. if (!$conn)
  28. die(sprintf("[001] %s\n", mysql_error()));
  29. if (!mysql_query("set wait_timeout=1", $conn))
  30. printf("[002] [%d] %s\n", mysql_errno($conn), mysql_error($conn));
  31. return $conn;
  32. }
  33. $conn = connect($host, $user, $passwd);
  34. $opened_files = -1;
  35. for ($i = 0; $i < 4; $i++) {
  36. /* wait while mysql closes connection */
  37. sleep(3);
  38. if (!mysql_ping($conn)) {
  39. printf("[003] reconnect %d\n", $i);
  40. $conn = connect($host, $user, $passwd);
  41. }
  42. $r = mysql_query('select 1', $conn);
  43. if (!$r)
  44. printf("[004] [%d] %s\n", mysql_errno($conn), mysql_error($conn));
  45. if ($opened_files == -1) {
  46. $opened_files = trim(exec("lsof -np " . getmypid() . " | wc -l"));
  47. printf("[005] Setting openened files...\n");
  48. } else if (($tmp = trim(exec("lsof -np " . getmypid() . " | wc -l"))) != $opened_files) {
  49. printf("[006] [%d] different number of opened_files : expected %d, got %d", $i, $opened_files, $tmp);
  50. } else {
  51. printf("[007] Opened files as expected\n");
  52. }
  53. }
  54. print "done!";
  55. ?>
  56. --EXPECTF--
  57. 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
  58. Warning: mysql_ping(): MySQL server has gone away in %s on line %d
  59. [003] reconnect 0
  60. 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
  61. [005] Setting openened files...
  62. Warning: mysql_ping(): MySQL server has gone away in %s on line %d
  63. [003] reconnect 1
  64. 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
  65. [007] Opened files as expected
  66. Warning: mysql_ping(): MySQL server has gone away in %s on line %d
  67. [003] reconnect 2
  68. 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
  69. [007] Opened files as expected
  70. Warning: mysql_ping(): MySQL server has gone away in %s on line %d
  71. [003] reconnect 3
  72. 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
  73. [007] Opened files as expected
  74. done!