I want to do periodic job(check row in DB) inside socket client I tried to do like in this issue https://github.com/reactphp/socket/issues/167
My code
$loop = \React\EventLoop\Loop::get();
$connector = new \React\Socket\Connector();
$connector->connect($host)->then(function (\React\Socket\ConnectionInterface $connection) use($loop){
$connection->on('connection', function () use($loop){
$loop->addPeriodicTimer(2, function () {
var_dump('test - periodic job');
});
});
$connection->write('test write');
$connection->on('data', function ($data) {
var_dump('test - data event');
});
});
So 'data event' works fine, but periodic job doesnt work
I tried second variant:
$loop = \React\EventLoop\Loop::get();
$loop->addPeriodicTimer(2, function () {
echo 'periodic event';
});
$connector = new \React\Socket\Connector([], $loop);
$connector->connect($host)->then(function (\React\Socket\ConnectionInterface $connection){
$connection->write($action);
$connection->on('data', function ($data) {
echo 'data event';
});
});
But in this case only periodic event works and I cannot receive any "data event"