golos-php-event-listener
PHP event listener for STEEM/GOLOS/VIZ/WHALESHARES blockchains event. It is scan blockchains for needed you transactions and handle it.
It is easy way catch some transactions and handle it.
Github or packagist with MIT license. Author
In Release v1.0.0
- Process control rebuild to t3ran13/php-process-manager
- DBManager was replaced with manager from t3ran13/php-process-manager
- New structure for BlockchainExplorerProcess
- New structure for EventHandler without EventListenerProcess
Process control rebuild to t3ran13/php-process-manager
It had own logic for working with processes. But it was not so convenient for development and using in projects. According this reasons lib uses outer process manager now - t3ran13/php-process-manager. It give new abstract layer and it is easy for understanding.
DBManager was replaced with manager from t3ran13/php-process-manager
DBManager is used for saving states of processes. t3ran13/php-process-manager has own DBManager witch is enough for our lib. Own DBManager was replaced with outer.
See t3ran13/php-process-manager to modify DBManager for your app, it is has method for saving some special data of events/process.
New stucture for Redis is
- DB0
- PM:GEV:{ProcessName}:{id}:className
- PM:GEV:{ProcessName}:{id}:processName
- PM:GEV:{ProcessName}:{id}:priority
- PM:GEV:{ProcessName}:{id}:pid
- PM:GEV:{ProcessName}:{id}:executionStep
- PM:GEV:{ProcessName}:{id}:isRunning
- PM:GEV:{ProcessName}:{id}:nTriesOfRun
- PM:GEV:{ProcessName}:{id}:maxNTriesOfRun
- PM:GEV:{ProcessName}:{id}:secondsBetweenRuns
- PM:GEV:{ProcessName}:{id}:maxLifetimeWithoutResults
- PM:GEV:{ProcessName}:{id}:lastUpdateDatetime
- PM:GEV:{ProcessName}:{id}:data:*
- PM:GEV:{ProcessName}:{id}:data:events:*
- PM:GEV:{ProcessName}:{id}:errors:*
New structure for BlockchainExplorerProcess
Thanks to using outer proces manager it has more less code and easy to modify logic if you need. Also it has new method addEvent for events handlers.
See below the example of usage
<?php
namespace MyApp;
use GolosPhpEventListener\app\process\BlockchainExplorerProcess;
use GolosPhpEventListener\app\process\EventsHandlersProcess;
use GrapheneNodeClient\Connectors\ConnectorInterface;
use ProcessManager\db\RedisManager;
use ProcessManager\ProcessManager;
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);
define('PATH', __DIR__);
require __DIR__ . "/Autoloader.php"; // only in GrapheneNodeClient project
require __DIR__ . '/vendor/autoload.php';
echo PHP_EOL . '------ start GOLOS EVENT LISTENER ------' . PHP_EOL;
$db = new RedisManager();
//Main process witch starts all other peocesses
$pm = (new ProcessManager($db))
->setProcessName('MainProcess')
->setMaxRunningProcesses(3); //it is 4 total with MainProcess, MAX 512 MB RAM by default
if ($pm->hasState()) {
$pm->loadState();
} else {
$pm->setPriority(25)
->setExecutionStep(1)
->setMaxNTriesOfRun(0)
->setSecondsBetweenRuns(55)
->setMaxLifetimeWithoutResults(20)
->saveState();
}
// creating event handler
$eh1 = (new PostIsCreatedEventHandler($db))
->setProcessName('GEV:votesOffafnur:1')
->generateIdFromProcessName()
->addCondition('op:1:voter','golosboard') //event trigger 1
->addCondition('op:0','vote'); //event trigger 2
if ($eh1->hasState()) {
$eh1->loadState();
} else {
$eh1->setPriority(35)
->setExecutionStep(1)
->setMaxNTriesOfRun(0)
->setSecondsBetweenRuns(10)
->setMaxLifetimeWithoutResults(15)
->saveState();
}
// creating event handler
$eh2 = (new PostIsCreatedEventHandler($db))
->setProcessName('GEV:allComments:2')
->generateIdFromProcessName()
->addCondition('op:0','comment'); //event trigger 1
if ($eh2->hasState()) {
$eh2->loadState();
} else {
$eh2->setPriority(35)
->setExecutionStep(1)
->setMaxNTriesOfRun(0)
->setSecondsBetweenRuns(10)
->setMaxLifetimeWithoutResults(15)
->saveState();
}
// creating event handler
$eh3 = (new PostIsCreatedEventHandler($db))
->setProcessName('GEV:allVotes:3')
->generateIdFromProcessName()
->addCondition('op:0','vote'); //event trigger 1
if ($eh3->hasState()) {
$eh3->loadState();
} else {
$eh3->setPriority(35)
->setExecutionStep(1)
->setMaxNTriesOfRun(0)
->setSecondsBetweenRuns(10)
->setMaxLifetimeWithoutResults(15)
->saveState();
}
// Creating blockchain lestener
$BEP = (new BlockchainExplorerProcess($db,ConnectorInterface::PLATFORM_STEEM))
->setProcessName('GEV:BlockchainExplorer')
->setLastBlock(16146488)
->addEvent($eh1) //do not forget add eventhandlers to explorer process
->addEvent($eh2) //adding event handler for detecting events
->addEvent($eh3);
if ($BEP->hasState()) {
$BEP->loadState();
} else {
$BEP->setPriority(30)
->setExecutionStep(1)
->setMaxNTriesOfRun(0)
->setSecondsBetweenRuns(30)
->setMaxLifetimeWithoutResults(20)
->saveState();
}
$pm->addProcess($BEP)
->addProcess($eh1)//add event listener for handling events
->addProcess($eh2)
->addProcess($eh3);
$pm->start();
Add this script to cron.
New structure for EventHandler without EventListenerProcess
The EventHandler is separate process now without central process (EventListenerProcess). It is easy to use and understanding.
Each event handler have to implements EventHandlerInterface and ProcessInterface, and each event have to be added to BlockchainExplorerProcess for detecting events and init as process for handling this events.
<?php
//....
$db = new RedisManager();
//Main process witch starts all other peocesses
$pm = (new ProcessManager($db));
//....
// creating event handler
$eh1 = (new PostIsCreatedEventHandler($db))
->setProcessName('GEV:votesOffafnur:1')
->generateIdFromProcessName()
->addCondition('op:1:voter','golosboard') //event trigger 1
->addCondition('op:0','vote'); //event trigger 2
if ($eh1->hasState()) {
$eh1->loadState();
} else {
$eh1->setPriority(35)
->setExecutionStep(1)
->setMaxNTriesOfRun(0)
->setSecondsBetweenRuns(10)
->setMaxLifetimeWithoutResults(15)
->saveState();
}
// Creating blockchain lestener
$BEP = (new BlockchainExplorerProcess($db,ConnectorInterface::PLATFORM_STEEM))
->addEvent($eh1); //adding event handler for detecting events
//...
$pm->addProcess($BEP)
->addProcess($eh1); //add event handler for handling events
$pm->start();
It is better with each commit
Commits were done by me for last 14 days
https://github.com/t3ran13/golos-php-event-listener/compare/v0.0.1rc3...v1.0.0
- fix getting of last block in block explorer process
- upd php-graphene-node-client version
- upd otrder login in BlockchainExplorerProcess (last 14 day)
- install composer t3ran13/php-process-manager (last 14 day)
- upd RedisManager are replaced by manager from t3ran13/php-process-manager (last 14 day)
- upd new EventHandlerAbstract (last 14 day)
- upd new BlockchainExplorerProcess (last 14 day)
- upd README (last 14 day)
- upd fix checking of conditions in event handler (last 14 day)
- upd hide logs output (last 14 day)
- upd fix t3ran13/php-process-manager version (last 14 day)
- upd sork events by adding order (last 14 day)