PHP code example of streamx / ingestion-client-php
1. Go to this page and download the library: Download streamx/ingestion-client-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/ */
streamx / ingestion-client-php example snippets
// Start your local StreamX instance.
// The sample assumes rest ingestion service is available at port 8080 and web server sink at port 8081.
// Create test page to be published to StreamX. It can be created as an associative array:
$page = ['content' => base64_encode('Hello, StreamX!')];
// It can also be created as a PHP object that follows the same schema:
class Page {
public string $content;
public function __construct(string $content) {
$this->content = base64_encode($content);
}
}
$page = new Page('Hello, StreamX!');
// Note: in both approaches, the content has to be in Base64 format.
// Create the client and a publisher dedicated to a specific channel:
$ingestionClient = \Streamx\Clients\Ingestion\Builders\StreamxClientBuilders::create('http://localhost:8080')->build();
$publisher = $ingestionClient->newPublisher();
// Publish page
$key = '/pages/page1.html';
$publishPageEvent = new \CloudEvents\V1\CloudEventImmutable(
'publish-event',
'my-source',
'com.streamx.blueprints.page.published.v1',
$page,
'application/json',
null, // data schema
$key
);
$publisher->send($publishPageEvent);
// Now the page should be available at http://localhost:8081/pages/page1.html
// Then, unpublish the page (data is not needed)
$unpublishPageEvent = new \CloudEvents\V1\CloudEventImmutable(
'unpublish-event',
'my-source',
'com.streamx.blueprints.page.unpublished.v1',
null, // data
null, // data content type
null, // data schema
$key
);
$publisher->send($unpublishPageEvent);
// Now the page should be unpublished from http://localhost:8081/pages/page1.html
bash
composer
bash
export XDEBUG_MODE=coverage
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.