1. Go to this page and download the library: Download leoplatform/php 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/ */
define('IN_LEO', true);
automatically load if in the same directory as this file. If not, explicitly load it:
new \Leo\lib\Config('./leo_config.php');
//create a Leo-sdk object
$leo = new Leo\Sdk("BotName");
//These are optional parameters, see the docs for possible values
$stream_options = [];
//function is called with every commit to the stream
//returns data about the checkpoint
$checkpoint_function = function ($checkpointData) {
var_dump($checkpointData);
};
// create a loader stream
$stream = $leo->createLoader($checkpoint_function, $stream_options);
for($i = 0; $i < 100000; $i++) {
$event = [
"id"=>"testing-$i",
"data"=>"some order data",
"other data"=>"some more data"
];
$meta = ["source"=>null, "start"=>$i];
//write an event to the stream
$stream->write("QueueName", $event, $meta);
}
$stream->end();
$bot_name = "EnrichmentBot";
$in_queue_name = "QueueName";
$enriched_queue_name = "EnrichedQueueName";
$read_options = ['limit'=>100000, 'run_time'=> "4 minutes"];
$transform_function = function ($event, $meta) {
var_dump($event);
$event["newdata"] = "this is some new data";
return $event;
};
$leo = new Leo\Sdk($bot_name, $config);
$stream = $leo->createEnrichment($in_queue_name, $transform_function, $enriched_queue_name, $read_options );
$bot_name = 'PHPOffloaderBot';
$queue_name = 'PHPEnrichedQueue';
$read_options = ['limit' => 500, 'run_time' => '4 minutes'];
$leo = new Leo\Sdk($bot_name);
$checkpointCount = $count = 0;
$reader = $leo->createOffloader($queue_name, $read_options);
foreach ($reader->events as $i => $event) {
$count++;
\Leo\lib\Utils::log($event);
// print out events so we can see them - for debugging
// print_r($event);
if (++$checkpointCount == 1000) {
$reader->checkpoint();
$checkpointCount = 0;
}
// sleep for 0.1 of a second to be able to read events as they pass through the command line - for debugging
// usleep(100000);
}
// checkpoint after we're done to tell the bot where we stopped last
$reader->checkpoint();
\Leo\lib\Utils::log(++$count);