1. Go to this page and download the library: Download magium/request-firehose library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
magium / request-firehose example snippets
\Magium\RequestFirehose\RequestFirehose::getInstance()->setAdapter(
new \Magium\RequestFirehose\Adapter\Filesystem\Filesystem('/tmp/logfile')
);
/**
* To watch this in action execute `redis-cli` and call `blpop ingestion`. Then run this file (`php push.php`). Use this method if you want to "persist" the data (ensure that you
* don't miss any, or if you want to round-robin data processing.
*/
\Magium\RequestFirehose\RequestFirehose::getInstance()->setAdapter(
new \Magium\RequestFirehose\Adapter\Redis\PushAdapter(
new \Predis\Client('tcp://127.0.0.1:6379'),
'ingestion'
)
);
/**
* To watch this in action execute `redis-cli` and call `subscribe ingestion`. Then run this file (`php publish.php`). Use this example if you do not want persistent data and/or
* want multiple subscribers to watch the data.
*/
\Magium\RequestFirehose\RequestFirehose::getInstance()->setAdapter(
new \Magium\RequestFirehose\Adapter\Redis\PublishAdapter(
new \Predis\Client('tcp://127.0.0.1:6379'),
'ingestion'
)
);
/**
* To watch this in action execute `redis-cli` and call `subscribe ingestion`. Then run
* `php -S 0.0.0.0:7777 publish_log_file.php`). Use this example if you do not want persistent data and/or
* want multiple subscribers to watch the data, or if you want to tail the log file for your entire cluster you can
* execute:
*
* stdbuf -oL redis-cli --raw subscribe ingestion | grep -v -E 'message|ingestion'
*/
\Magium\RequestFirehose\RequestFirehose::getInstance()->setAdapter(
new \Magium\RequestFirehose\Adapter\Redis\PublishAdapter(
new \Predis\Client('tcp://127.0.0.1:6379'),
'ingestion',
0,
new \Magium\RequestFirehose\Filter\LogfileFilter()
)
);
/**
* To watch this in action log in to your MongoDB instance and execute this file. Once you have executed this file
* check your mongo DB. You should see the results there.
*/
$client = new \MongoDB\Client();
$collection = $client->selectCollection('analysis', 'requests');
\Magium\RequestFirehose\RequestFirehose::getInstance()->setAdapter(
new \Magium\RequestFirehose\Adapter\MongoDb\MongoDb(
$collection
)
);
/**
* Run this file (`php filesystem.php`). Run `tail -f /tmp/testfile` to watch the output.
*/
\Magium\RequestFirehose\RequestFirehose::getInstance()->setAdapter(
new \Magium\RequestFirehose\Adapter\Filesystem\Filesystem('/tmp/testfile')
);
/**
* To watch this in action execute `redis-cli` and call `subscribe ingestion`. Then run
* `php -S 0.0.0.0:7777 publish_log_file.php`. Use this example if you want to watch your system by grepping
* the Redis subscription output, but also want to store the requests in MongoDB for later analysis.
*
* stdbuf -oL redis-cli --raw subscribe ingestion | grep -v -E 'message|ingestion'
*
*/
$aggregate = new \Magium\RequestFirehose\Adapter\Aggregate\AggregateAdapter();
$aggregate[] = new \Magium\RequestFirehose\Adapter\Redis\PublishAdapter(
new \Predis\Client('tcp://127.0.0.1:6379'),
'ingestion',
0,
new \Magium\RequestFirehose\Filter\LogfileFilter()
);
$client = new \MongoDB\Client();
$collection = $client->selectCollection('analysis', 'requests');
$aggregate[] = new \Magium\RequestFirehose\Adapter\MongoDb\MongoDb(
$collection
);
\Magium\RequestFirehose\RequestFirehose::getInstance()->setAdapter($aggregate);
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.