Added single-threaded and multi-threaded example
This commit is contained in:
parent
da6abceed2
commit
040426a63c
9 changed files with 110 additions and 15 deletions
19
tests/multi_threaded.php
Normal file
19
tests/multi_threaded.php
Normal file
|
@ -0,0 +1,19 @@
|
|||
<?php
|
||||
|
||||
require __DIR__ . DIRECTORY_SEPARATOR . 'autoload.php';
|
||||
import('net.nosial.tamerlib');
|
||||
|
||||
$bot = new TgBotLib\Bot(getenv('BOT_TOKEN'));
|
||||
TamerLib\Tamer::init(\TamerLib\Abstracts\ProtocolType::Gearman, ['127.0.0.1:4730']);
|
||||
TamerLib\Tamer::addWorker(__DIR__ . DIRECTORY_SEPARATOR . 'worker.php', 10);
|
||||
|
||||
var_dump('Starting workers');
|
||||
TamerLib\Tamer::startWorkers();
|
||||
|
||||
while(true)
|
||||
{
|
||||
foreach($bot->getUpdates() as $update)
|
||||
{
|
||||
TamerLib\Tamer::do(TamerLib\Objects\Task::create('handle_update', json_encode($update->toArray())));
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue