Esempio n. 1
0
<?php

require __DIR__ . '/../vendor/autoload.php';
use ShortFlake\IdGenerator;
$loop = React\EventLoop\Factory::create();
$id_generator = new IdGenerator($loop);
$context = new React\ZMQ\Context($loop);
$socket = $context->getSocket(ZMQ::SOCKET_REP);
$socket->bind('tcp://127.0.0.1:1337');
$socket->on('message', function ($message) use($id_generator, $socket) {
    if ('id' == $message) {
        $id_generator->computeId()->then(function ($uuid) use($socket) {
            $socket->send($uuid);
        });
    }
});
$loop->run();
Esempio n. 2
0
<?php

require __DIR__ . '/../vendor/autoload.php';
use React\Socket\Connection;
use ShortFlake\IdGenerator;
$loop = React\EventLoop\Factory::create();
$id_generator = new IdGenerator($loop);
// id socket
$id_socket = new React\Socket\Server($loop);
$id_socket->listen(1337);
$id_socket->on('connection', function (Connection $conn) use($id_generator) {
    $id_generator->computeId()->then(function ($uuid) use($conn) {
        // uuid is an integer
        $conn->end($uuid);
    });
});
// metric socket
$metric_socket = new React\Socket\Server($loop);
$metric_socket->listen(1338);
$metric_socket->on('connection', function (Connection $conn) use($id_generator) {
    $mem = memory_get_usage(TRUE);
    $conn->write('No of Ids: ' . $id_generator->getTotalGeneratedIds() . PHP_EOL);
    $conn->write('Mem Usage: ' . $mem . 'Bytes, ' . round($mem / 1024 / 104) . 'M' . PHP_EOL);
    $conn->end();
});
$loop->run();