Advertisement
kriks

mysqli connection in CLOSE_WAIT state when forked

Jul 9th, 2014
23
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.78 KB | None | 0 0
  1. <?php
  2.  
  3. $asyncTest = new asyncTest();
  4. $asyncTest->treatElement();
  5.  
  6. class asyncTest
  7. {
  8.   private $db;
  9.   public function __construct()
  10.   {
  11.     echo "New asyncTest (" . getmypid() . ")\n";
  12.     $this->db = mysqli_init();
  13.     $this->db->real_connect('127.0.0.1', 'user', 'pass', 'db');
  14.   }
  15.  
  16.   public function __destruct()
  17.   {
  18.     $this->disconnect();
  19.   }
  20.  
  21.   public function disconnect()
  22.   {
  23.     if(isset($this->db))
  24.     {
  25.       $threadId = $this->db->thread_id;
  26.       if($threadId)
  27.       {
  28.         $this->db->kill($threadId);
  29.       }
  30.       $this->db->close();
  31.       unset($this->db);
  32.     }
  33.   }
  34.  
  35.   public function treatElement()
  36.   {
  37.     sleep(1);
  38.     //$this->disconnect();
  39.     exec("php -d display_errors=on -f conn.php >> conn.log 2>&1  < /dev/null &");
  40.   }
  41.  
  42. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement