Pili Streaming Cloud Library for PHP | Generated by AI

Home PDF

Key Points

Installation

First, ensure you have Composer installed. Add the package to your composer.json file with:

"require": {
    "pili-engineering/pili-sdk-php": "dev-master"
}

Then, run composer install or composer update. In your PHP script, include:

require 'vendor/autoload.php';

Setup and Usage

You’ll need a Qiniu account and a Pili Hub. Set your access key, secret key, and hub name, then create a Hub object:

use Qiniu\Credentials;
use Pili\Hub;

$credentials = new Credentials('your_access_key', 'your_secret_key');
$hub = new Hub($credentials, 'your_hub_name');

Create or get a stream, e.g., $stream = $hub->createStream('your_stream_key');, and use methods like $stream->rtmpPublishUrl(60) for operations.

Unexpected Detail

Note that “dev-master” is a development version, potentially unstable, with tagged versions like 1.5.5 available for production.


Comprehensive Guide on Using “pili-engineering/pili-sdk-php”: “dev-master”

This guide provides a detailed exploration of how to use the “pili-engineering/pili-sdk-php” package with the “dev-master” version, based on available documentation and examples. It covers installation, setup, usage, and additional considerations, ensuring a thorough understanding for developers working with Pili Streaming Cloud services.

Background and Context

The “pili-engineering/pili-sdk-php” package is a server-side library for PHP, designed to interact with Pili Streaming Cloud, a service associated with Qiniu, a cloud storage and CDN provider. The “dev-master” version refers to the latest development branch, which may include recent features but could be less stable than tagged releases. The package requires PHP 5.3.0 or higher, making it accessible for many PHP environments as of March 3, 2025.

Installation Process

To begin, you must have Composer installed, a dependency manager for PHP. The installation involves adding the package to your project’s composer.json file and running a Composer command to download it. Specifically:

This process ensures the package is integrated into your project, leveraging Composer’s autoloading for easy class access.

Prerequisites and Setup

Before using the SDK, you need a Qiniu account and must set up a Pili Hub, as the SDK interacts with Pili Streaming Cloud services. This involves obtaining an Access Key and Secret Key from Qiniu and creating a hub within their platform. The documentation suggests these credentials are essential for authentication.

To set up, define your credentials in your PHP script:

An example setup looks like:

$accessKey = 'your_access_key';
$secretKey = 'your_secret_key';
$hubName = 'your_hub_name';

Creating and Using the Hub Object

The core of the SDK is the Hub object, which facilitates stream management. First, create a Credentials object using your Qiniu keys:

use Qiniu\Credentials;

$credentials = new Credentials($accessKey, $secretKey);

Then, instantiate a Hub object with these credentials and your hub name:

use Pili\Hub;

$hub = new Hub($credentials, $hubName);

This Hub object allows you to perform various stream-related operations, such as creating, retrieving, or listing streams.

Working with Streams

Streams are central to Pili Streaming Cloud, and the SDK provides methods to manage them through the Hub object. To create a new stream:

$streamKey = 'your_stream_key'; // Must be unique within the hub
$stream = $hub->createStream($streamKey);

To retrieve an existing stream:

$stream = $hub->getStream($streamKey);

The stream object then offers various methods for operations, detailed in the following table based on available documentation:

Operation Method Description
Create Stream $hub->createStream($key) Creates a new stream with the given key.
Get Stream $hub->getStream($key) Retrieves an existing stream by key.
List Streams $hub->listStreams($marker, $limit, $prefix) Lists streams with pagination options.
RTMP Publish URL $stream->rtmpPublishUrl($expire) Generates an RTMP publish URL with expiration time.
RTMP Play URL $stream->rtmpPlayUrl() Generates an RTMP play URL for the stream.
HLS Play URL $stream->hlsPlayUrl() Generates an HLS play URL for streaming.
Disable Stream $stream->disable() Disables the stream.
Enable Stream $stream->enable() Enables the stream.
Get Stream Status $stream->status() Retrieves the current status of the stream.

For example, to generate an RTMP publish URL with a 60-second expiration:

$expire = 60;
$url = $stream->rtmpPublishUrl($expire);
echo $url;

This URL can be used for publishing streams to Pili Streaming Cloud, with the expiration ensuring temporary access.

Additional Considerations

Comparative Insights

Comparing with other Pili SDKs, such as the Python version, reveals similar patterns: both require credentials, hub setup, and stream operations. The PHP version, however, uses an object-oriented approach with Hub and Stream classes, contrasting with Python’s more functional style. This aligns with PHP’s typical development practices, offering type safety and IDE support.

Conclusion

Using “pili-engineering/pili-sdk-php”: “dev-master” involves installing via Composer, setting up Qiniu credentials, creating a Hub object, and managing streams with methods like rtmpPublishUrl. Ensure your environment meets PHP 5.3.0+ requirements and consider stability for production use. This guide provides a comprehensive starting point, with further details available in the official documentation and repository.

Key Citations


Back 2025.03.04 Donate