summaryrefslogtreecommitdiff
path: root/ext/mysql/tests
diff options
context:
space:
mode:
authorAndrey Hristov <andrey@php.net>2011-08-22 10:42:43 +0000
committerAndrey Hristov <andrey@php.net>2011-08-22 10:42:43 +0000
commit0aa6354a2d14b5e477fcb7cb7c4d370aeefd012a (patch)
treebf8d9d7f0428ab006382375572b477bbb63ea5ef /ext/mysql/tests
parent1d4f05bb31480069fb5c9fa71d0a71c8047d6de9 (diff)
downloadphp-git-0aa6354a2d14b5e477fcb7cb7c4d370aeefd012a.tar.gz
Fix Bug #55473 mysql_pconnect leaks file descriptors on reconnect
The fix is for now in 5_4 and trunk, to be merged into 5_3 after 5.3.8 is packaged (expected today). The test case goes to all branches
Diffstat (limited to 'ext/mysql/tests')
-rw-r--r--ext/mysql/tests/bug55473.phpt68
1 files changed, 68 insertions, 0 deletions
diff --git a/ext/mysql/tests/bug55473.phpt b/ext/mysql/tests/bug55473.phpt
new file mode 100644
index 0000000000..8d42744fdf
--- /dev/null
+++ b/ext/mysql/tests/bug55473.phpt
@@ -0,0 +1,68 @@
+--TEST--
+Bug #5547 (mysql_pconnect leaks file descriptors on reconnect)
+--SKIPIF--
+<?php
+require_once('skipif.inc');
+require_once('skipifconnectfailure.inc');
+?>
+--INI--
+mysql.max_persistent=30
+mysql.allow_persistent=1
+--FILE--
+<?php
+ include "connect.inc";
+
+ $tmp = NULL;
+ $link = NULL;
+
+ function connect($host, $user, $passwd) {
+ $conn = mysql_pconnect($host, $user, $passwd);
+ if (!$conn)
+ die(mysql_error()."\n");
+ mysql_query("set wait_timeout=1", $conn);
+ return $conn;
+ }
+
+ $conn = connect($host, $user, $passwd);
+ $opened_files = -1;
+ for($i = 0; $i < 4; $i++) {
+ /* wait while mysql closes connection */
+ sleep(3);
+
+ if (!mysql_ping($conn)) {
+ echo "reconnect\n";
+ $conn = connect($host, $user, $passwd);
+ }
+
+ $r = mysql_query('select 1', $conn);
+ $error = $r ? 'OK' : mysql_error();
+ if ($opened_files == -1) {
+ $opened_files = trim(exec("lsof -np " . getmypid() . " | wc -l"));
+ echo "OK\n";
+ } else if (($tmp = trim(exec("lsof -np " . getmypid() . " | wc -l"))) != $opened_files) {
+ printf("[01] [%d] different number of opened_files : expected %d, got %d", $i, $opened_files, $tmp);
+ } else {
+ echo "OK\n";
+ }
+ }
+
+
+ print "done!";
+?>
+--EXPECTF--
+Warning: mysql_ping(): MySQL server has gone away in %s on line %d
+reconnect
+OK
+
+Warning: mysql_ping(): MySQL server has gone away in %s on line %d
+reconnect
+OK
+
+Warning: mysql_ping(): MySQL server has gone away in %s on line %d
+reconnect
+OK
+
+Warning: mysql_ping(): MySQL server has gone away in %s on line %d
+reconnect
+OK
+done! \ No newline at end of file