Skip to content

Commit

Permalink
http://memememomo.hatenablog.com/entry/2011/11/28/204308
Browse files Browse the repository at this point in the history
memememomoさんの指摘を反映
正常に終了しなかった場合でも、PHPの終了時にPIDが設定されていればTERMを送るようにした
  • Loading branch information
taiyoh committed Jul 18, 2012
1 parent 0982786 commit 43d457c
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion Test_mysqld.php
Expand Up @@ -26,7 +26,7 @@ public function __construct($my_cnf = array(), $opts = array())
: $opts['base_dir'];
}
else {
$this->base_dir = sys_get_temp_dir() . '/' . sha1(microtime());
$this->base_dir = sys_get_temp_dir() . '/' . $this->_owner_pid;
}

$this->my_cnf = array_merge(array(
Expand Down Expand Up @@ -125,6 +125,7 @@ public function start()
usleep(100000);
}
$this->pid = $pid;
define("TEST_MYSQLD_CHILD_PID", $pid);
$db = new PDO($this->dsn(array('dbname' => 'mysql')), 'root');
$db->exec('CREATE DATABASE IF NOT EXISTS test');
}
Expand Down Expand Up @@ -255,4 +256,16 @@ protected function rm_rf($dir)
rmdir($dir);
return true;
}

public static function __shutdown()
{
if (defined("TEST_MYSQLD_CHILD_PID")) {
$pid = constant("TEST_MYSQLD_CHILD_PID");
$status = 0;
posix_kill($pid, SIGTERM);
while (pcntl_waitpid($pid, $status) <= 0) {}
}
}
}

register_shutdown_function('Test_mysqld::__shutdown');

0 comments on commit 43d457c

Please sign in to comment.