45 lines
994 B
PHP
45 lines
994 B
PHP
|
|
<?php
|
||
|
|
|
||
|
|
namespace Mine\SeekerBundle\Periodic;
|
||
|
|
|
||
|
|
use Doctrine\DBAL\Driver\PDOException;
|
||
|
|
use Doctrine\ORM\EntityManager;
|
||
|
|
use Gos\Bundle\WebSocketBundle\Periodic\PeriodicInterface;
|
||
|
|
|
||
|
|
class MinePeriodic implements PeriodicInterface
|
||
|
|
{
|
||
|
|
private $em;
|
||
|
|
|
||
|
|
public function __construct(EntityManager $entityManager)
|
||
|
|
{
|
||
|
|
$this->em = $entityManager;
|
||
|
|
}
|
||
|
|
|
||
|
|
/**
|
||
|
|
* This function is executed every 5 seconds.
|
||
|
|
*
|
||
|
|
* For more advanced functionality, try injecting a Topic Service to perform actions on your connections every x seconds.
|
||
|
|
*/
|
||
|
|
public function tick()
|
||
|
|
{
|
||
|
|
try {
|
||
|
|
$connection = $this->em->getConnection();
|
||
|
|
|
||
|
|
if (false === $connection->ping()) {
|
||
|
|
$connection->close();
|
||
|
|
$connection->connect();
|
||
|
|
}
|
||
|
|
} catch(PDOException $ex) {
|
||
|
|
throw PDOException::class;
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
/**
|
||
|
|
* {@inheritdoc}
|
||
|
|
*/
|
||
|
|
public function getTimeout()
|
||
|
|
{
|
||
|
|
return 777;
|
||
|
|
}
|
||
|
|
}
|