PHPackages                             pili-engineering/pili-sdk-php - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. pili-engineering/pili-sdk-php

ActiveLibrary

pili-engineering/pili-sdk-php
=============================

Pili Streaming Cloud server-side library for PHP.

v1.5.5(9y ago)735.4k29[4 issues](https://github.com/pili-engineering/pili-sdk-php/issues)[3 PRs](https://github.com/pili-engineering/pili-sdk-php/pulls)MITPHPPHP &gt;=5.3.0

Since May 14Pushed 8y ago24 watchersCompare

[ Source](https://github.com/pili-engineering/pili-sdk-php)[ Packagist](https://packagist.org/packages/pili-engineering/pili-sdk-php)[ Docs](https://github.com/pili-engineering/pili-sdk-php)[ RSS](/packages/pili-engineering-pili-sdk-php/feed)WikiDiscussions master Synced today

READMEChangelog (7)Dependencies (2)Versions (11)Used By (0)

Pili Streaming Cloud server-side library for PHP
================================================

[](#pili-streaming-cloud-server-side-library-for-php)

Features
--------

[](#features)

- Stream Create,Get,List
    - $hub-&gt;createStream()
    - $hub-&gt;getStream()
    - $hub-&gt;listStreams()
- Stream operations else
    - stream-&gt;toJSONString()
    - stream-&gt;update()
    - stream-&gt;disable()
    - stream-&gt;enable()
    - stream-&gt;status()
    - stream-&gt;rtmpPublishUrl()
    - stream-&gt;rtmpLiveUrls()
    - stream-&gt;hlsLiveUrls()
    - stream-&gt;httpFlvLiveUrls()
    - stream-&gt;segments()
    - stream-&gt;hlsPlaybackUrls()
    - stream-&gt;snapshot()
    - stream-&gt;saveAs()
    - stream-&gt;delete()

Contents
--------

[](#contents)

- [Installation](#installation)
- [Usage](#usage)
    - [Configuration](#configuration)
    - [Hub](#hub)
        - [Instantiate a Pili Hub object](#instantiate-a-pili-hub-object)
        - [Create a new Stream](#create-a-new-stream)
        - [Get a Stream](#get-a-stream)
        - [List Streams](#List-streams)
    - [Stream](#stream)
        - [To JSON string](#to-json-string)
        - [Update a Stream](#update-a-stream)
        - [Disable a Stream](#disable-a-stream)
        - [Enable a Stream](#enable-a-stream)
        - [Get Stream status](#get-stream-status)
        - [Generate RTMP publish URL](#generate-rtmp-publish-url)
        - [Generate RTMP live play URLs](#generate-rtmp-live-play-urls)
        - [Generate HLS live play URLs](generate-hls-live-play-urls)
        - [Generate Http-Flv live play URLs](generate-http-flv-live-play-urls)
        - [Get Stream segments](#get-stream-segments)
        - [Generate HLS playback URLs](generate-hls-playback-urls)
        - [Save Stream as a file](#save-stream-as-a-file)
        - [Snapshot Stream](#snapshot-stream)
        - [Delete a Stream](#delete-a-stream)
- [History](#history)

Installaion
-----------

[](#installaion)

### Requirements

[](#requirements)

- PHP &gt;= 5.3.0

### Install with Composer

[](#install-with-composer)

If you're using [Composer](http://getcomposer.org) to manage dependencies, you can add pili-sdk-php with it.

```
# Install Composer
curl -sS https://getcomposer.org/installer | php
```

You can add Pili as a dependency using the `composer.phar` CLI:

```
php composer.phar require pili-engineering/pili-sdk-php:dev-master
```

Alternatively, you can specify pili-sdk-php as a dependency in your project's existing `composer.json` file:

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

After installing, you need to require Composer's autoloader:

```
require 'vendor/autoload.php';
```

You can find out more on how to install Composer, configure autoloading, and other best-practices for defining dependencies at .

### Install source from GitHub

[](#install-source-from-github)

The `pili-sdk-php` requires PHP `v5.3+`. Download the PHP library from Github, and require in your script like so:

To install the source code:

```
$ git clone https://github.com/pili-engineering/pili-sdk-php.git
```

And include it in your scripts:

```
require_once '/path/to/pili-sdk-php/lib/Pili.php';
```

### Install source from zip/tarball

[](#install-source-from-ziptarball)

Alternatively, you can fetch a [tarball](https://github.com/pili-engineering/pili-sdk-php/tarball/master) or [zipball](https://github.com/pili-engineering/pili-sdk-php/zipball/master):

```
$ curl -L https://github.com/pili-engineering/pili-sdk-php/tarball/master | tar xzv

(or)

$ wget https://github.com/pili-engineering/pili-sdk-php/tarball/master -O - | tar xzv
```

And include it in your scripts:

```
require_once '/path/to/pili-sdk-php/lib/Pili.php';
```

Usage
-----

[](#usage)

### Configuration

[](#configuration)

```
// Replace with your keys here
define('ACCESS_KEY', 'Qiniu_AccessKey');
define('SECRET_KEY', 'Qiniu_SecretKey');

// Replace with your hub name
define('HUB', 'Pili_Hub_Name'); // The Hub must be exists before use

// Change API host as necessary
//
// pili.qiniuapi.com as default
// pili-lte.qiniuapi.com is the latest RC version
//
// $cfg = \Pili\Config::getInstance();
// $cfg->API_HOST = 'pili.qiniuapi.com'; // default
```

### Hub

[](#hub)

#### Instantiate a Pili Hub object

[](#instantiate-a-pili-hub-object)

```
// Instantiate an Hub object
$credentials = new \Qiniu\Credentials(ACCESS_KEY, SECRET_KEY); #=> Credentials Object
$hub = new \Pili\Hub($credentials, HUB); # => Hub Object
```

#### Create a new Stream

[](#create-a-new-stream)

```
try {

    $title           = NULL;     // optional, auto-generated as default
    $publishKey      = NULL;     // optional, auto-generated as default
    $publishSecurity = NULL;     // optional, can be "dynamic" or "static", "dynamic" as default

    $stream = $hub->createStream($title, $publishKey, $publishSecurity); # => Stream Object

    echo "createStream() =>\n";
    var_export($stream);
    echo "\n\n";

} catch (Exception $e) {
    echo 'createStream() failed. Caught exception: ',  $e->getMessage(), "\n";
}
/*
Pili\Stream::__set_state(array(
   '_data' =>
  array (
    'id' => 'z1.coding.55d7a219e3ba5723280000b5',
    'createdAt' => '2015-08-21T18:11:37.057-04:00',
    'updatedAt' => '2015-08-21T18:32:05.186076957-04:00',
    'title' => '55d7a219e3ba5723280000b5',
    'hub' => 'coding',
    'disabled' => false,
    "publishKey":"734de946-11e0-487a-8627-30bf777ed5a3",
    "publishSecurity":"dynamic",
    'hosts' =>
    array (
      'publish' =>
      array (
        'rtmp' => 'pili-publish.example.com',
      ),
      'live' =>
      array (
        'rtmp' => 'pili-live-rtmp.example.com',
        'hls' => 'pili-live-hls.example.com',
        'hdl' => 'pili-live-hdl.example.com',
      ),
      'playback' =>
      array (
        'hls' => 'pili-playback.example.com',
      ),
    ),
  ),
))
*/
```

#### Get a Stream

[](#get-a-stream)

```
try {

    $streamId = $stream->id;

    $stream = $hub->getStream($streamId); # => Stream Object

    echo "getStream() =>\n";
    var_export($stream);
    echo "\n\n";

} catch (Exception $e) {
    echo "getStream() failed. Caught exception: ",  $e->getMessage(), "\n";
}
/*
Pili\Stream::__set_state(array(
   '_data' =>
  array (
    'id' => 'z1.coding.55d7a219e3ba5723280000b5',
    'createdAt' => '2015-08-21T18:11:37.057-04:00',
    'updatedAt' => '2015-08-21T18:32:05.186076957-04:00',
    'title' => '55d7a219e3ba5723280000b5',
    'hub' => 'coding',
    'disabled' => false,
    "publishKey":"734de946-11e0-487a-8627-30bf777ed5a3",
    "publishSecurity":"dynamic",
    'hosts' =>
    array (
      'publish' =>
      array (
        'rtmp' => 'pili-publish.example.com',
      ),
      'live' =>
      array (
        'rtmp' => 'pili-live-rtmp.example.com',
        'hls' => 'pili-live-hls.example.com',
        'hdl' => 'pili-live-hdl.example.com',
      ),
      'playback' =>
      array (
        'hls' => 'pili-playback.example.com',
      ),
    ),
  ),
))
*/
```

#### List Streams

[](#list-streams)

```
try {

    $marker       = NULL;      // optional
    $limit        = NULL;      // optional
    $title_prefix = NULL;      // optional
    $status       = NULL;      // optional, "connected" only

    $result = $hub->listStreams($marker, $limit, $title_prefix, $status); # => Array

    echo "listStreams() =>\n";
    var_export($result);
    echo "\n\n";

} catch (Exception $e) {
    echo "listStreams() failed. Caught exception: ",  $e->getMessage(), "\n";
}
/*
array (
  'marker' => '2',
  'end' => true,
  'items' =>
  array (
      0 => Stream Object,
      1 => Stream Object,
  )
)
*/
```

### Stream

[](#stream)

#### To JSON string

[](#to-json-string)

```
$result = $stream->toJSONString(); # => string
echo "Stream toJSONString() =>\n";
var_export($result);
echo "\n\n";
/*
'{
    "id":"z1.coding.55d7a219e3ba5723280000b5",
    "createdAt":"2015-08-21T18:11:37.057-04:00",
    "updatedAt":"2015-08-21T18:30:32.548-04:00",
    "title":"55d7a219e3ba5723280000b5",
    "hub":"coding",
    "disabled":false,
    "publishKey":"734de946-11e0-487a-8627-30bf777ed5a3",
    "publishSecurity":"dynamic",
    "hosts":{
        "publish":{"rtmp":"pili-publish.example.com"},
        "live":{
            "rtmp":"pili-live-rtmp.example.com",
            "hls":"pili-live-hls.example.com",
            "hdl":"pili-live-hdl.example.com"
        },
        "playback":{
            "hls":"pili-playback.example.com"
        }
    }
}'
*/
```

### Update a Stream

[](#update-a-stream)

```
try {

    $stream->publishKey      = 'new_secret_words'; // optional
    $stream->publishSecurity = 'static';           // optional, can be "dynamic" or "static"
    $stream->disabled        = NULL;               // optional, can be "true" of "false"

    $stream = $stream->update(); # => Stream Object

    echo "Stream update() =>\n";
    var_export($stream);
    echo "\n\n";

} catch (Exception $e) {
    echo "Stream update() failed. Caught exception: ",  $e->getMessage(), "\n";
}
/*
Pili\Stream::__set_state(array(
   '_data' =>
  array (
    'id' => 'z1.coding.55d7a219e3ba5723280000b5',
    'createdAt' => '2015-08-21T18:11:37.057-04:00',
    'updatedAt' => '2015-08-21T18:32:05.186076957-04:00',
    'title' => '55d7a219e3ba5723280000b5',
    'hub' => 'coding',
    'disabled' => false,
    'publishKey' => 'new_secret_words',
    'publishSecurity' => 'static',
    'hosts' =>
    array (
      'publish' =>
      array (
        'rtmp' => 'pili-publish.example.com',
      ),
      'live' =>
      array (
        'rtmp' => 'pili-live-rtmp.example.com',
        'hls' => 'pili-live-hls.example.com',
        'hdl' => 'pili-live-hdl.example.com',
      ),
      'playback' =>
      array (
        'hls' => 'pili-playback.example.com',
      ),
    ),
  ),
))
*/
```

#### Disable a Stream

[](#disable-a-stream)

```
$disabledTill = time() + 10; # disabled in 10s from now
$result = $stream->disable($disabledTill); # => NULL
echo "Stream disable() =>\n";
var_export($result);
echo "\n\n";
/*
true
*/
```

#### Enable a Stream

[](#enable-a-stream)

```
$result = $stream->enable(); # => NULL
echo "Stream enable() =>\n";
var_export($result);
echo "\n\n";
/*
false
*/
```

#### Get Stream status

[](#get-stream-status)

```
try {

    $result = $stream->status(); # => Array

    echo "Stream status() =>\n";
    var_export($result);
    echo "\n\n";

} catch (Exception $e) {
    echo "Stream status() failed. Caught exception: ",  $e->getMessage(), "\n";
}
/*
array (
  "reqId" => "YmMxOTcuAAASDc1n",
  "hub" => "coding",
  "stream" => "2b20838cdb214448b7c7eef46abf1a0a",
  "startFrom" => "2015-12-03T12:24:30.226Z",
  'addr' => '222.73.202.226:2572',
  'status' => 'connected',
  'bytesPerSecond' => 16870.200000000001,
  'framesPerSecond' =>
  array (
    'audio' => 42.200000000000003,
    'video' => 14.733333333333333,
    'data' => 0.066666666666666666,
  ),
)
*/
```

#### Generate RTMP publish URL

[](#generate-rtmp-publish-url)

```
$publishUrl = $stream->rtmpPublishUrl();
echo "Stream rtmpPublishUrl() =>\n";
echo $publishUrl;
echo "\n\n";
/*
rtmp://pili-publish.example.com/coding/55d7a219e3ba5723280000b5?key=new_secret_words
*/
```

#### Generate RTMP live play URLs

[](#generate-rtmp-live-play-urls)

```
$urls = $stream->rtmpLiveUrls();
echo "Stream rtmpLiveUrls() =>\n";
var_export($urls);
echo "\n\n";
/*
array (
  'ORIGIN' => 'rtmp://pili-live-rtmp.example.com/coding/55d7a219e3ba5723280000b5',
)
*/
```

#### Generate HLS play live URLs

[](#generate-hls-play-live-urls)

```
$urls = $stream->hlsLiveUrls();
echo "Stream hlsLiveUrls() =>\n";
var_export($urls);
echo "\n\n";
/*
array (
  'ORIGIN' => 'http://pili-live-hls.example.com/coding/55d7a219e3ba5723280000b5.m3u8',
)
*/
```

#### Generate Http-Flv live play URLs

[](#generate-http-flv-live-play-urls)

```
$urls = $stream->httpFlvLiveUrls();
echo "Stream httpFlvLiveUrls() =>\n";
var_export($urls);
echo "\n\n";
/*
array (
  'ORIGIN' => 'http://pili-live-hdl.example.com/coding/55d7a219e3ba5723280000b5.flv',
)
*/
```

#### Get Stream segments

[](#get-stream-segments)

```
try {

    $start = NULL;    // optional, in second, unix timestamp
    $end   = NULL;    // optional, in second, unix timestamp
    $limit = NULL;    // optional, uint

    $result = $stream->segments($start, $end, $limit); # => Array

    echo "Stream segments() =>\n";
    var_export($result);
    echo "\n\n";

} catch (Exception $e) {
    echo "Stream segments() failed. Caught exception: ",  $e->getMessage(), "\n";
}
/*
array (
  'start' => 1440196065,
  'end' => 1440198092,
  'segments' =>
  array (
    0 =>
    array (
      'start' => 1440196065,
      'end' => 1440196124,
    ),
    1 =>
    array (
      'start' => 1440198072,
      'end' => 1440198092,
    ),
  ),
)
*/
```

#### Generate HLS playback URLs

[](#generate-hls-playback-urls)

```
$start     = 1440196065;  // optional, in second, unix timestamp
$end       = 1440196105;  // optional, in second, unix timestamp

$urls = $stream->hlsPlaybackUrls($start, $end);
echo "Stream hlsPlaybackUrls() =>\n";
var_export($urls);
echo "\n\n";
/*
array (
  'ORIGIN' => 'http://pili-playback.example.com/coding/55d7a219e3ba5723280000b5.m3u8?start=-1&end=-1',
)
*/
```

#### Save Stream as a file

[](#save-stream-as-a-file)

```
try {

    $name      = 'videoName.mp4'; // required
    $format    = NULL;            // optional
    $start     = -1;              // optional, in second, unix timestamp
    $end       = -1;              // optional, in second, unix timestamp
    $notifyUrl = NULL;            // optional
    $pipeline  = NULL;            // optional

    $result = $stream->saveAs($name, $format, $start, $end, $notifyUrl, $pipeline); # => Array

    echo "Stream saveAs() =>\n";
    var_export($result);
    echo "\n\n";

} catch (Exception $e) {
    echo "Stream saveAs() failed. Caught exception: ",  $e->getMessage(), "\n";
}
/*
array (
  'url' => 'http://pili-media.example.com/recordings/z1.coding.55d7a219e3ba5723280000b5/videoName.m3u8',
  'targetUrl' => 'http://pili-vod.example.com/recordings/z1.coding.55d7a219e3ba5723280000b5/videoName.mp4',
  'persistentId' => 'z1.55d7a6e77823de5a49a8899b',
)
*/
```

While invoking `saveAs()` and `snapshot()`, you can get processing state via Qiniu FOP Service using `persistentId`.
API: `curl -D GET http://api.qiniu.com/status/get/prefop?id={PersistentId}`
Doc reference:

#### Snapshot Stream

[](#snapshot-stream)

```
try {

    $name      = 'imageName.jpg'; // required
    $format    = 'jpg';           // required
    $time      = NULL;            // optional, in second, unix timestamp
    $notifyUrl = NULL;            // optional
    $pipeline  = NULL;            // optional

    $result = $stream->snapshot($name, $format, $time, $notifyUrl, $pipeline); # => Array

    echo "Stream snapshot() =>\n";
    var_export($result);
    echo "\n\n";

} catch (Exception $e) {
    echo "Stream snapshot() failed. Caught exception: ",  $e->getMessage(), "\n";
}
/*
array (
  'targetUrl' => 'http://pili-static.example.com/snapshots/z1.coding.55d7a219e3ba5723280000b5/imageName.jpg',
  'persistentId' => 'z1.55d7a6e77823de5a49a8899a',
)
*/
```

#### Delete a Stream

[](#delete-a-stream)

```
try {
    $result = $stream->delete(); # => NULL
    echo "Stream delete() =>\n";
    var_dump($result);
    echo "\n\n";
} catch (Exception $e) {
    echo "Stream delete() failed. Caught exception: ",  $e->getMessage(), "\n";
}
/*
NULL
*/
```

History
-------

[](#history)

- 1.5.4

    - Use $stream-&gt;saveAs in $stream-&gt;hlsPlaybackUrls
- 1.5.3

    - Update $stream-&gt;disable($disabledTill)
- 1.5.2

    - Update $stream-&gt;rtmpPublishUrl()
- 1.5.1

    - Update API
        - $hub-&gt;listStreams($marker=NULL, $limit=NULL, $title\_prefix=NULL, $status=NULL)
        - $stream-&gt;saveAs($name, $format=NULL, $start=NULL, $end=NULL, $notifyUrl=NULL, $pipeline=NULL)
        - $stream-&gt;snapshot($name, $format, $time=NULL, $notifyUrl=NULL, $pipeline=NULL)
        - $stream-&gt;hlsPlaybackUrls($start=-1, $end=-1)
- 1.5.0

    - Add Credentials and Transport class
    - Renamed $client to $hub
- 1.4.0

    - Add Stream Create,Get,List
        - $hub-&gt;createStream()
        - $hub-&gt;getStream()
        - $hub-&gt;listStreams()
    - Add Stream operations else
        - $stream-&gt;toJSONString()
        - $stream-&gt;update()
        - $stream-&gt;disable()
        - $stream-&gt;enable()
        - $stream-&gt;status()
        - $stream-&gt;segments()
        - $stream-&gt;rtmpPublishUrl()
        - $stream-&gt;rtmpLiveUrls()
        - $stream-&gt;hlsLiveUrls()
        - $stream-&gt;httpFlvLiveUrls()
        - $stream-&gt;hlsPlaybackUrls()
        - $stream-&gt;snapshot()
        - $stream-&gt;saveAs()
        - $stream-&gt;delete()

###  Health Score

38

—

LowBetter than 86% of packages

Maintenance19

Infrequent updates — may be unmaintained

Popularity34

Limited adoption so far

Community24

Small or concentrated contributor base

Maturity64

Established project with proven stability

 Bus Factor1

Top contributor holds 87.7% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~55 days

Recently: every ~74 days

Total

10

Last Release

3462d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/b2ab96b03236376b53e7f562f82eff3c2f6d9c8d42e32dee43c9d4d8e80c8a61?d=identicon)[qiniusdk](/maintainers/qiniusdk)

![](https://www.gravatar.com/avatar/98ed22445f4bec99c22d127afee250cfff1dd667f8c497f52bcc0a87746157c6?d=identicon)[why404](/maintainers/why404)

---

Top Contributors

[![why404](https://avatars.githubusercontent.com/u/35111?v=4)](https://github.com/why404 "why404 (100 commits)")[![longbai](https://avatars.githubusercontent.com/u/1204301?v=4)](https://github.com/longbai "longbai (8 commits)")[![googollee](https://avatars.githubusercontent.com/u/496526?v=4)](https://github.com/googollee "googollee (3 commits)")[![blankyao](https://avatars.githubusercontent.com/u/108237?v=4)](https://github.com/blankyao "blankyao (2 commits)")[![carter2000](https://avatars.githubusercontent.com/u/1518851?v=4)](https://github.com/carter2000 "carter2000 (1 commits)")

---

Tags

cloudweb servicestreamingqiniuhlsdashrtmppilihdlhds

###  Code Quality

TestsPHPUnit

Code StylePHP\_CodeSniffer

### Embed Badge

![Health badge](/badges/pili-engineering-pili-sdk-php/health.svg)

```
[![Health](https://phpackages.com/badges/pili-engineering-pili-sdk-php/health.svg)](https://phpackages.com/packages/pili-engineering-pili-sdk-php)
```

###  Alternatives

[pili-engineering/pili-sdk-php.v2

Pili Streaming Cloud Server-Side Library For PHP.

4665.4k](/packages/pili-engineering-pili-sdk-phpv2)[aminyazdanpanah/php-ffmpeg-video-streaming

📼 PHP FFMpeg - Video Streaming - DASH, HLS http://video.aminyazdanpanah.com

544269.4k6](/packages/aminyazdanpanah-php-ffmpeg-video-streaming)[qiniu/php-sdk

Qiniu Resource (Cloud) Storage SDK for PHP

8473.0M219](/packages/qiniu-php-sdk)[zgldh/qiniu-laravel-storage

Qiniu Resource (Cloud) Storage SDK for Laravel 5/6/7/8/9

530391.9k12](/packages/zgldh-qiniu-laravel-storage)[opencoconut/coconut

Coconut is a Cloud Video Encoding Service built for developers

17471.3k2](/packages/opencoconut-coconut)[itbdw/laravel-storage-qiniu

A storage library for laravel5 and qiniu sdk

7515.2k](/packages/itbdw-laravel-storage-qiniu)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
