Last active
November 8, 2021 14:41
-
-
Save ludofleury/5074595 to your computer and use it in GitHub Desktop.
A Behat Context with a hook to kill the Mysql connections
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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'])); | |
} | |
} | |
} | |
} | |
} |
Thanks soooooo much @ludofleury. You saved my day after a Symfony 2.5 / PHP 5.5 upgrade! ;)
that was a life saver! I thought that unsetting the PDO connection was enough but it was not.
thanks for this
You’re welcome, happy to help!
On Tue 25 Feb 2020 at 14:23, Javi Aguilar ***@***.***> wrote:
that was a life saver! I thought that unsetting the PDO connection was
enough but it was not.
thanks for this
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
<https://gist.github.com/5074595?email_source=notifications&email_token=AABNVHXWJKETB5YYD7QB56LREULVRA5CNFSM4K3IZK32YY3PNVWWK3TUL52HS4DFVNDWS43UINXW23LFNZ2KUY3PNVWWK3TUL5UWJTQAGCT4O#gistcomment-3188679>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AABNVHXUMM5CZVOCTTKNESDREULVRANCNFSM4K3IZK3Q>
.
--
*Ludovic Fleury*
Paris, France.
Budapest, Hungary.
+33 6 18 50 47 24
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks @beberlei for the tips, I'll try.