summaryrefslogtreecommitdiff
path: root/ext/mysql/tests/bug55473.phpt
diff options
context:
space:
mode:
authorLorry Tar Creator <lorry-tar-importer@baserock.org>2013-03-14 05:42:27 +0000
committer <>2013-04-03 16:25:08 +0000
commitc4dd7a1a684490673e25aaf4fabec5df138854c4 (patch)
tree4d57c44caae4480efff02b90b9be86f44bf25409 /ext/mysql/tests/bug55473.phpt
downloadphp2-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/bug55473.phpt')
-rw-r--r--ext/mysql/tests/bug55473.phpt79
1 files changed, 79 insertions, 0 deletions
diff --git a/ext/mysql/tests/bug55473.phpt b/ext/mysql/tests/bug55473.phpt
new file mode 100644
index 0000000..befecef
--- /dev/null
+++ b/ext/mysql/tests/bug55473.phpt
@@ -0,0 +1,79 @@
+--TEST--
+Bug #55473 (mysql_pconnect leaks file descriptors on reconnect)
+--SKIPIF--
+<?php
+require_once('skipif.inc');
+require_once('skipifconnectfailure.inc');
+if (defined('PHP_WINDOWS_VERSION_MAJOR')) {
+ die("skip Test doesn't work on Windows");
+}
+
+if (!($output = @exec("lsof -nwp " . getmypid())))
+ die("skip Test can't find command line tool lsof");
+?>
+--INI--
+mysql.max_persistent=30
+mysql.allow_persistent=1
+--FILE--
+<?php
+ include "connect.inc";
+
+ $tmp = NULL;
+ $link = NULL;
+
+ if ($socket)
+ $host = sprintf("%s:%s", $host, $socket);
+ else if ($port)
+ $host = sprintf("%s:%s", $host, $port);
+
+ function connect($host, $user, $passwd) {
+ $conn = mysql_pconnect($host, $user, $passwd);
+
+ if (!$conn)
+ die(sprintf("[001] %s\n", mysql_error()));
+
+ if (!mysql_query("set wait_timeout=1", $conn))
+ printf("[002] [%d] %s\n", mysql_errno($conn), mysql_error($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)) {
+ printf("[003] reconnect %d\n", $i);
+ $conn = connect($host, $user, $passwd);
+ }
+
+ $r = mysql_query('select 1', $conn);
+ if (!$r)
+ printf("[004] [%d] %s\n", mysql_errno($conn), mysql_error($conn));
+
+
+ if ($opened_files == -1) {
+ $opened_files = trim(exec("lsof -nwp " . getmypid() . " | wc -l"));
+ printf("[005] Setting openened files...\n");
+ } else if (($tmp = trim(exec("lsof -nwp " . getmypid() . " | wc -l"))) != $opened_files) {
+ printf("[006] [%d] different number of opened_files : expected %d, got %d", $i, $opened_files, $tmp);
+ } else {
+ printf("[007] Opened files as expected\n");
+ }
+ }
+
+ print "done!";
+?>
+--EXPECTF--
+[003] reconnect 0
+[005] Setting openened files...
+[003] reconnect 1
+[007] Opened files as expected
+[003] reconnect 2
+[007] Opened files as expected
+[003] reconnect 3
+[007] Opened files as expected
+done!