From:             
Operating system: 
PHP version:      5.3.7
Package:          MySQL related
Bug Type:         Bug
Bug description:mysql_pconnect leaks file descriptors on reconnect

Description:
------------
Whem Mysql closes created by mysql_pconnect() peristent connection, file
descriptor lefts opened and is never reused.
I have a server that stops working due to opened file descriptors limit.

Test script:
---------------
<?php

function connect($passwd) {
   $conn = mysql_pconnect('localhost:3306','root', $passwd);
   if (!$conn)
      die(mysql_error()."\n");
   mysql_query("set wait_timeout=5", $conn);
   return $conn;
}

$passwd = $argv[1];
$conn = connect($passwd);

for($i=0;$i<10;$i++) {
   /* wait while mysql closes connection */
   sleep(6);

   if (!mysql_ping($conn)) {
      echo "reconnect\n";
      $conn = connect($passwd);
   }

   $r = mysql_query('select 1', $conn);
   $error = $r ? 'OK' : mysql_error();
   $opened_files = trim(exec("lsof -np " . getmypid() . " | wc -l"));
   echo "$error. opened files: $opened_files\n";
}

?>


Expected result:
----------------
$ php ./test.php
reconnect
OK. opened files: 76
reconnect
OK. opened files: 76
reconnect
OK. opened files: 76
reconnect
OK. opened files: 76
...

Actual result:
--------------
$ php ./test.php
reconnect
OK. opened files: 76
reconnect
OK. opened files: 77
reconnect
OK. opened files: 78
reconnect
OK. opened files: 79
...

-- 
Edit bug report at https://bugs.php.net/bug.php?id=55473&edit=1
-- 
Try a snapshot (PHP 5.4):            
https://bugs.php.net/fix.php?id=55473&r=trysnapshot54
Try a snapshot (PHP 5.3):            
https://bugs.php.net/fix.php?id=55473&r=trysnapshot53
Try a snapshot (trunk):              
https://bugs.php.net/fix.php?id=55473&r=trysnapshottrunk
Fixed in SVN:                        
https://bugs.php.net/fix.php?id=55473&r=fixed
Fixed in SVN and need be documented: 
https://bugs.php.net/fix.php?id=55473&r=needdocs
Fixed in release:                    
https://bugs.php.net/fix.php?id=55473&r=alreadyfixed
Need backtrace:                      
https://bugs.php.net/fix.php?id=55473&r=needtrace
Need Reproduce Script:               
https://bugs.php.net/fix.php?id=55473&r=needscript
Try newer version:                   
https://bugs.php.net/fix.php?id=55473&r=oldversion
Not developer issue:                 
https://bugs.php.net/fix.php?id=55473&r=support
Expected behavior:                   
https://bugs.php.net/fix.php?id=55473&r=notwrong
Not enough info:                     
https://bugs.php.net/fix.php?id=55473&r=notenoughinfo
Submitted twice:                     
https://bugs.php.net/fix.php?id=55473&r=submittedtwice
register_globals:                    
https://bugs.php.net/fix.php?id=55473&r=globals
PHP 4 support discontinued:          
https://bugs.php.net/fix.php?id=55473&r=php4
Daylight Savings:                    https://bugs.php.net/fix.php?id=55473&r=dst
IIS Stability:                       
https://bugs.php.net/fix.php?id=55473&r=isapi
Install GNU Sed:                     
https://bugs.php.net/fix.php?id=55473&r=gnused
Floating point limitations:          
https://bugs.php.net/fix.php?id=55473&r=float
No Zend Extensions:                  
https://bugs.php.net/fix.php?id=55473&r=nozend
MySQL Configuration Error:           
https://bugs.php.net/fix.php?id=55473&r=mysqlcfg

Reply via email to