prggmr is an event processing engine for PHP 5.4. designed to be lightweight, fast and very simple to use.
<?php
prggmr\handle(function(){
echo "The light is green go!";
}, 'light.green');
<?php
prggmr\signal('light.green');
<?php
prggmr\signal_interrupt(function(){
echo "Inserting some data into the event for handles..";
$this->data = "HelloWorld";
}, 'light.green', prggmr\Engine::INTERRUPT_PRE);
<?php
prggmr\signal_interrupt(function(){
echo "Checking what happened in the handle";
}, 'light.green', prggmr\Engine::INTERRUPT_POST);
<?php
var_dump(prggmr\event_history());
<?php
$engine = new prggmr\Engine();
<?php
$engine->handle(function(){
echo "The light is green go!";
}, 'light.green');
<?php
$engine->signal('light.green');
<?php
$engine->signal_interrupt(function(){
echo "Inserting some data into the event for handles..";
$this->data = "HelloWorld";
}, 'light.green', prggmr\Engine::INTERRUPT_PRE);
<?php
$engine->signal_interrupt(function(){
echo "Checking what happened in the handle";
}, 'light.green', prggmr\Engine::INTERRUPT_POST);
<?php
var_dump($engine->event_history());
Depending on your needs prggmr can be installed using two different methods.
Include the following in your composer.json
file.
{
"require": {
"prggmr/prggmr": "1.*.*"
}
}
Run the installer.
$ curl -s http://getcomposer.org/installer | php
$ php composer.phar install
And include the library
<?php
require_once 'vendor/prggmr/prggmr/src/prggmr.php';
This method is recommended if you are building multiple applications on a server
Download the latest release and run the following command in the prggmr folder.
sudo ./install
And include the library
<?php
require_once 'prggmr/src/prggmr.php';
Documentation is available at prggmr.org
The prggmr mailing list is located here mailing list.
prggmr uses semver you should too.
The following signals are on the development roadmap.
CRON based time signals based on http://docs.oracle.com/cd/E14592_01/doc.10142/e14611/cron_expressions.htm
<?php
// every 15 minutes
prggmr\handle(function(){
}, new prggmr\signal\time\Cron('*/15 * * * *'));
// 23:00:00 every weekday night
prggmr\handle(function(){
} new prggmr\signal\time\Cron('0 23 ? * MON-FRI'));
// 10:15 everyday
prggmr\handle(function(){
}, new prggmr\signal\time\Cron('0 15 10 * * ?'));
W3C Event-Stream (Specs)[http://dev.w3.org/html5/eventsource/].
<?php
$socket = new \prggmr\signal\http\EventStream();
handle(function($bytes){
// do something
}, $socket->read());
handle(function($bytes){
// do something
}, $socket->write());
This will allow for non-blocking event driven I/O using file descriptors or networking socktes.
<?php
$socket = new \prggmr\signal\io\Socket('127.0.0.1', 8888);
handle(function($bytes){
echo "Read bytes";
echo $bytes;
}, $socket->read(1024));
handle(function($bytes){
echo "Writing bytes";
echo $bytes;
}, $socket->write());
handle(function($client){
echo "Client connected";
echo $client->ip_address;
}, $socket->connect());
handle(function($client){
echo "Client disconnected";
echo $client->ip_address;
}, $socket->disconnect());