Skip to content

Instantly share code, notes, and snippets.

@ludofleury
Last active November 8, 2021 14:41
Show Gist options
  • Select an option

  • Save ludofleury/5074595 to your computer and use it in GitHub Desktop.

Select an option

Save ludofleury/5074595 to your computer and use it in GitHub Desktop.
A Behat Context with a hook to kill the Mysql connections
<?php
use Behat\Symfony2Extension\Context\KernelAwareInterface;
use Behat\Symfony2Extension\Context\KernelDictionary;
use Behat\MinkExtension\Context\MinkContext;
class MysqlContext extends MinkContext implements KernelAwareInterface
{
use KernelDictionary;
/**
* @AfterScenario
*/
public function killMysqlConnections()
{
$connections = $this->kernel->getContainer()->get('doctrine')->getConnections();
foreach ($connections as $connection) {
$threads = $connection->query('SHOW FULL PROCESSLIST');
while ($thread = $threads->fetch()) {
if ($thread['db'] == $connection->getDatabase() && $thread['Command'] == 'Sleep') {
$connection->query(sprintf('KILL %d', $thread['Id']));
}
}
}
}
}
@ludofleury
Copy link
Copy Markdown
Author

ludofleury commented Mar 20, 2020 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment