public function sendAsReact($data) { $loop = \React\EventLoop\Factory::create(); $tcpConnector = new \React\SocketClient\TcpConnector($loop); $tcpConnector->create('127.0.0.1', 4001)->then(function (\React\Stream\Stream $stream) use($data) { $stream->write($data); $stream->end(); }); $loop->run(); }
<?php require __DIR__ . '/vendor/autoload.php'; define('DOCUMENT_ROOT', dirname(__FILE__)); gc_enable(); use Movim\Bootstrap; //memprof_enable(); $bootstrap = new Bootstrap(); $booted = $bootstrap->boot(); $loop = React\EventLoop\Factory::create(); $connector = new React\SocketClient\TcpConnector($loop); $stdin = new React\Stream\Stream(STDIN, $loop); fwrite(STDERR, colorize(getenv('sid'), 'yellow') . " widgets before : " . \sizeToCleanSize(memory_get_usage()) . "\n"); // We load and register all the widgets $wrapper = \Movim\Widget\Wrapper::getInstance(); $wrapper->registerAll($bootstrap->getWidgets()); fwrite(STDERR, colorize(getenv('sid'), 'yellow') . " widgets : " . \sizeToCleanSize(memory_get_usage()) . "\n"); $conn = null; $parser = new \Moxl\Parser(); $buffer = ''; $timestamp = time(); function handleSSLErrors($errno, $errstr) { fwrite(STDERR, colorize(getenv('sid'), 'yellow') . " : " . colorize($errstr, 'red') . "\n"); } // Temporary linker killer $loop->addPeriodicTimer(5, function () use(&$conn, &$timestamp) { if ($timestamp < time() - 3600 * 6) { $conn->close(); } });
<?php require dirname(__DIR__) . '/vendor/autoload.php'; $loop = React\EventLoop\Factory::create(); $tcpConnector = new React\SocketClient\TcpConnector($loop); $tcpConnector->create('10.6.1.119', 1337)->then(function (React\Stream\Stream $stream) { $facility = array('LOG_AUTH', 'LOG_AUTHPRIV', 'LOG_CRON', 'LOG_DAEMON', 'LOG_LOCAL0', 'LOG_LOCAL1'); $severity = array('LOG_EMERG', 'LOG_ALERT', 'LOG_CRIT', 'LOG_ERR', 'LOG_WARNING', 'LOG_NOTICE', 'LOG_INFO', 'LOG_DEBUG'); $programs = array('anacron', 'CRON', 'dhclient', 'kernel', 'laptop-mode', 'mtp-probe', 'NetworkManager', 'ntpd', 'rsyslogd'); while (1) { $delay = usleep(200000); $host = 'srv-' . sprintf('%02d', rand(0, 9)); $timestamp = time(); $loc_severity = $severity[rand(0, count($severity) - 1)]; $loc_facility = $facility[rand(0, count($facility) - 1)]; $loc_progname = $programs[rand(0, count($programs) - 1)]; $tag = $loc_progname . sprintf("[%d]", rand(12000, 64000)); $message = ""; for ($i = 1; $i < rand(20, 50); $i++) { $message .= chr(rand(97, 122)); } $text = "{"; $text .= "rows: 0,"; $text .= "timestamp: " . $timestamp . ","; $text .= "received: " . $timestamp . ","; $text .= "message: \"" . $message . "\","; $text .= "host: \"" . $host . "\","; $text .= "severity: \"" . $loc_severity . "\","; $text .= "facility: \"" . $loc_facility . "\","; $text .= "programname: \"" . $loc_progname . "\","; $text .= "tag: \"" . $tag . "\"";