Download the PHP package magium/request-firehose without Composer
On this page you can find all versions of the php package magium/request-firehose. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download magium/request-firehose
More information about magium/request-firehose
Files in magium/request-firehose
Package request-firehose
Short Description A simple library to push request metadata into a collection service (like Redis) from multiple sources
License Apache-2.0
Informations about the package request-firehose
PHP Request Firehose
This library attaches itself to the PHP request and upon request shutdown it will send the request meta data or a log file entry to an adapter, currently Redis or Mongo, where it can be stored, processed or tailed. It is intended for use in clustered systems where multiple machines are serving HTTP requests and, in general, where devops would like to have a centralized place for monitoring or storing requests that can be used alongside other logging tools.
For example, if you wanted to tail
and grep
the logs for a specific IP address you would deploy the Redis publish code (see below) and run the following command:
To install
To Use
Introduction
Call \Magium\RequestFirehose\RequestFirehose::getInstance()
at the earliest convenience in your script. This will typically be immediately after require_once 'vendor/autoload.php';
.
Once you have an instance of the firehose you will need to configure an adapter for it. The simples example is with the Filesystem
adapter.
That's it! It will register itself as a shutdown function and write to the appropriate adapter after the request has completed.
If you are not using Composer, or are using some other autoloader that is not compatible with PSR-4 you can include the src/include.php
file and it will load up all of the source files.
If you are using Redis, MongoDB, or some other adapter that is not part of core PHP you may need to install their client library. Check the composer suggestions for supported clients.
Check out some of the examples in the examples directory. The following examples have been largely copied from there.
Redis
Push (BLPOP)
PubSub (SUBSCRIBE)
PubSub /w Log Output
If you are looking for something you can simply tail and pipe to grep, this might be a good option.
MongoDB
Filesystem
Aggregate
Perhaps there are times when you would like to push the data to Redis so you can tail the logs, but also store the data in Mongo for processing. You can use the Aggregate adapter to do that.