PHP code example of murnieza / amazon-kinesis-client-library-php
1. Go to this page and download the library: Download murnieza/amazon-kinesis-client-library-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/ */
murnieza / amazon-kinesis-client-library-php example snippets
`
use Aws\Kinesis\KinesisClient;
use Aws\Common\Enum\Region;
use Rf\Aws\AutoLoader;
use Rf\Aws\Kinesis\ClientLibrary\KinesisProxy;
use Rf\Aws\Kinesis\ClientLibrary\KinesisShardFileDataStore;
use Rf\Aws\Kinesis\ClientLibrary\KinesisShardMemcacheDataStore;
use Rf\Aws\Kinesis\ClientLibrary\KinesisStorageManager;
define('STREAM_NAME', 'kinesis-trial');
$kinesis = KinesisClient::factory(array(
'key' => 'XXXXX',
'secret' => 'XXXXX',
'region' => Region::VIRGINIA
));
$kinesis_proxy = KinesisProxy::factory($kinesis, STREAM_NAME);
while (true) {
$sample_data = date('YmdHis');
$kinesis_proxy->putRecord($sample_data, mt_rand(1, 1000000));
echo $sample_data, PHP_EOL;
sleep(1);
}
`
s\Kinesis\KinesisClient;
use Aws\Common\Enum\Region;
use Rf\Aws\AutoLoader;
use Rf\Aws\Kinesis\ClientLibrary\KinesisProxy;
use Rf\Aws\Kinesis\ClientLibrary\KinesisShardFileDataStore;
use Rf\Aws\Kinesis\ClientLibrary\KinesisShardMemcacheDataStore;
use Rf\Aws\Kinesis\ClientLibrary\KinesisStorageManager;
define('STREAM_NAME', 'kinesis-trial');
$kinesis = KinesisClient::factory(array(
'key' => 'XXXXX',
'secret' => 'XXXXX',
'region' => Region::VIRGINIA
));
$memcache = new Memcache();
$memcache->addServer("localhost", 11211);
$kinesis_proxy = KinesisProxy::factory($kinesis, STREAM_NAME);
$kinesis_storage_manager = new KinesisStorageManager($kinesis_proxy, new KinesisShardMemcacheDataStore($memcache));
$data_records = $kinesis_storage_manager->findWithMergeStoreDataRecords(null, 10, 5);
foreach ($data_records as $data_record) {
echo $data_record->getData(), PHP_EOL;
}
$kinesis_storage_manager->saveAll();
`
\Kinesis\KinesisClient;
use Aws\Common\Enum\Region;
use Rf\Aws\AutoLoader;
use Rf\Aws\Kinesis\ClientLibrary\KinesisProxy;
use Rf\Aws\Kinesis\ClientLibrary\KinesisShardFileDataStore;
use Rf\Aws\Kinesis\ClientLibrary\KinesisShardMemcacheDataStore;
use Rf\Aws\Kinesis\ClientLibrary\KinesisStorageManager;
define('STREAM_NAME', 'kinesis-trial');
$kinesis = KinesisClient::factory(array(
'key' => 'XXXXX',
'secret' => 'XXXXX',
'region' => Region::VIRGINIA
));
$kinesis_proxy = KinesisProxy::factory($kinesis, STREAM_NAME);
$kinesis_storage_manager = new KinesisStorageManager($kinesis_proxy, new KinesisShardFileDataStore('/tmp/amazon-kinesis'));
$data_records = $kinesis_storage_manager->findWithMergeStoreDataRecords(null, 10, 5);
foreach ($data_records as $data_record) {
echo $data_record->getData(), PHP_EOL;
}
$kinesis_storage_manager->saveAll();
`
AutoLoader::register();
`
$data_records = $kinesis_storage_manager->findWithMergeStoreDataRecords('shardId-000000000000', 1000, 10);