Skip to content
Go to file

Latest commit


Git stats


Failed to load latest commit information.
Latest commit message
Commit time


PHP event listener for STEEM/GOLOS blockchains

Install Via Composer

composer require t3ran13/golos-php-event-listener

Basic Usage

For working you app you need

  • database manager
  • events handlers
  • start script for cron

Example below

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);
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))
    ->setMaxRunningProcesses(3); //it is 4 total with MainProcess, MAX 512 MB RAM by default
if ($pm->hasState()) {
} else {

// creating event handler
$eh1 = (new PostIsCreatedEventHandler($db))
    ->addCondition('op:1:voter','golosboard') //event trigger 1
    ->addCondition('op:0','vote'); //event trigger 2
if ($eh1->hasState()) {
} else {

// creating event handler
$eh2 = (new PostIsCreatedEventHandler($db))
    ->addCondition('op:0','comment'); //event trigger 1
if ($eh2->hasState()) {
} else {

// creating event handler
$eh3 = (new PostIsCreatedEventHandler($db))
    ->addCondition('op:0','vote'); //event trigger 1
if ($eh3->hasState()) {
} else {

// Creating blockchain lestener
$BEP = (new BlockchainExplorerProcess($db,ConnectorInterface::PLATFORM_GOLOS))
    ->addEvent($eh1) //do not forget add eventhandlers to explorer process
    ->addEvent($eh2) //adding event handler for detecting events
if ($BEP->hasState()) {
} else {

    ->addProcess($eh1)//add event listener for handling events

Add this script to cron.

Database manager

Lib use ready for using RedisManager from t3ran13/php-process-manager composer package, with next DB structure:

- 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:*

How to create onw DB manager, see t3ran13/php-process-manager

Events handlers

Each Handler have to implements EventHandlerInterface and ProcessManager\process\ProcessInterface, you can create onw or extends from EventHandlerAbstract. When any event are found BlockchainExplorer make checking with isTrxSatisfiesConditions function and save to handling list if is it satisfied. When EventHandlerProcess starts it handle all events from queue.

namespace MyApp;

use GolosPhpEventListener\app\process\handlers\EventHandlerAbstract;

class VoteHandler extends EventHandlerAbstract
    public function start()
        $events = $this->getEvents(); //TODO FIXME
        echo PHP_EOL . date('Y-m-d H:i:s') . $this->getProcessName() . ' is running and have total events='
            . count($events);

        foreach ($events as $key => $event) {
            // some code
            $this->setLastUpdateDatetime(date('Y-m-d H:i:s'))

     * ask process to start
     * @return bool
    public function isStartNeeded(): bool
        return parent::isStartNeeded()
            && count($this->getEvents()) > 0;


Example of the app base on golos-php-event-listener you can see here

You can’t perform that action at this time.