In the destructor of my test environment class I want do drop the test database. Executing this code in a ordinary method works fine.
Putting it into the destructor (or using register_shutdown_function) works as well but it causes my php process to never finish. Investigating the code with xdebug reveils, that echo 'finished'; is never reached.
Any ideas why this causes the php process to hang?
public function __destruct()
{
$config = $this->getConfiguration();
if ($config['dbtests']['autogenerate'] && $config['dbtests']['cleanup'] ) {
/** @var \PDO $dbh */
$dbh = new \PDO('mysql:host=' . $config['database']['host'], $config['database']['user'], $config['database']['password']);
$dbh->exec('DROP DATABASE ' . $config['database']['dbname']);
echo 'finished';
}
}
As mentioned, this code is from my test environment class. This is used to test doctrine entities.
I found that I have to mannualy close the db connection of the doctrine
EntityManagerbefore opening an other connection to this db. This is likely because I’m deleting the db which the connection of theEntitiyManageris pointing to.The problem is not realted to
__destructorregister_shutdown_function. I’ve been able to reproduce and finally fix the problem with ordinary user code.