PHPackages                             pili-engineering/pili-sdk-php.v2 - 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. [API Development](/categories/api)
4. /
5. pili-engineering/pili-sdk-php.v2

ActiveLibrary[API Development](/categories/api)

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

Pili Streaming Cloud Server-Side Library For PHP.

v2.1.1(8y ago)4665.4k—0%30[3 issues](https://github.com/pili-engineering/pili-sdk-php.v2/issues)[1 PRs](https://github.com/pili-engineering/pili-sdk-php.v2/pulls)MITPHPPHP &gt;=5.3.0

Since Mar 11Pushed 6y ago9 watchersCompare

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

READMEChangelog (2)Dependencies (2)Versions (3)Used By (0)

Pili Streaming Cloud Server-Side Library For PHP
================================================

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

Features
--------

[](#features)

- URL
    - RTMP推流地址: RTMPPublishURL(domain, hub, streamKey, mac, expireAfterSeconds)
    - RTMP直播地址: RTMPPlayURL(domain, hub, streamKey)
    - HLS直播地址: HLSPlayURL(domain, hub, streamKey)
    - HDL直播地址: HDLPlayURL(domain, hub, streamKey)
    - 截图直播地址: SnapshotPlayURL(domain, hub, streamKey)
- Hub
    - 创建流: hub-&gt;create(streamKey)
    - 获得流: hub-&gt;stream(streamKey)
    - 列出流: hub-&gt;listLiveStreams(prefix, limit, marker)
    - 列出正在直播的流: hub-&gt;listStreams(prefix, limit, marker)
- Stream
    - 流信息: stream-&gt;info()
    - 启用流: stream-&gt;enable()
    - 禁用流: stream-&gt;disable()
    - 查询直播状态: stream-&gt;liveStatus()
    - 保存直播回放: stream-&gt;save(start, end)
    - 查询直播历史: stream-&gt;historyActivity(start, end)
- Room
    - 创建房间: room-&gt;createRoom()
    - 查看房间: room-&gt;getRoom()
    - 删除房间: room-&gt;deleteRoom()
    - 生成房间token: room-&gt;roomToken()

Contents
--------

[](#contents)

- [Installation](#installation)
- [Usage](#usage)
    - [Configuration](#configuration)
    - [URL](#url)
        - [Generate RTMP publish URL](#generate-rtmp-publish-url)
        - [Generate RTMP play URL](#generate-rtmp-play-url)
        - [Generate HLS play URL](#generate-hls-play-url)
        - [Generate HDL play URL](#generate-hdl-play-url)
        - [Generate snapshot play URL](#generate-snapshot-play-url)
    - [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)
        - [List live streams](#list-live-streams)
    - [Stream](#stream)
        - [Get stream info](#get-stream-info)
        - [Disable a stream](#disable-a-stream)
        - [Enable a stream](#enable-a-stream)
        - [Get stream live status](#get-stream-live-status)
        - [Get stream history activity](#get-stream-history-activity)
        - [Save stream live playback](#save-stream-live-playback)
    - [Room](#room)
        - [Create a room](#create-a-room)
        - [Get a room](#get-a-room)
        - [Delete a room](#delete-a-room)
        - [Generate a room token](#generate-a-room-token)

Installation
------------

[](#installation)

### 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.v2: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.v2": "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.v2.git
```

And include it in your scripts:

```
require_once '/path/to/pili-sdk-php/lib/Pili_v2.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.v2/tarball/master | tar xzv

(or)

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

And include it in your scripts:

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

Usage
-----

[](#usage)

### Configuration

[](#configuration)

```
    // 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
```

### Url

[](#url)

#### Generate RTMP publish URL

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

```
    $url=$stream->RTMPPublishURL("publish-rtmp.test.com", $hubName, $streamKey, 3600,$ak,$sk);
    /*
    rtmp://publish-rtmp.test.com/PiliSDKTest/streamkey?e=1463023142&token=7O7hf7Ld1RrC_fpZdFvU8aCgOPuhw2K4eapYOdII:-5IVlpFNNGJHwv-2qKwVIakC0ME=
    */
```

#### Generate RTMP play URL

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

```
    $url=$stream->RTMPPlayURL("live-rtmp.test.com", $hubName, $streamKey);
    /*
    rtmp://live-rtmp.test.com/PiliSDKTest/streamkey
    */
```

#### Generate HLS play URL

[](#generate-hls-play-url)

```
    $url=$stream->HLSPlayURL("live-hls.test.com", $hubName, $streamKey);
    /*
    http://live-hls.test.com/PiliSDKTest/streamkey.m3u8
    */
```

#### Generate HDL play URL

[](#generate-hdl-play-url)

```
    $url=$stream->HDLPlayURL("live-hdl.test.com", $hubName, $streamKey);
    /*
    http://live-hdl.test.com/PiliSDKTest/streamkey.flv
    */
```

#### Generate snapshot play URL

[](#generate-snapshot-play-url)

```
    $url=$stream->SnapshotPlayURL("live-snapshot.test.com", $hubName, $streamKey);
    /*
    http://live-snapshot.test.com/PiliSDKTest/streamkey.jpg
    */
```

### Hub

[](#hub)

#### Instantiate a pili hub object

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

```
    // Instantiate an Hub object
    $ak = "7O7hf7Ld1RrC_fpZdFvU8aCgOPuhw2K4eapYOdII";
    $sk = "6Rq7rMSUHHqOgo0DJjh15tHsGUBEH9QhWqqyj4ka";
    $hubName = "PiliSDKTest";
    $mac = new Qiniu\Pili\Mac($ak, $sk);
    $client = new Qiniu\Pili\Client($mac);
    $hub = $client->hub($hubName);
```

#### Create a new stream

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

```
    try{
        $streamKey="php-sdk-test".time();
        $resp=$hub->create($streamKey);
        print_r($resp);
    }catch(\Exception $e) {
             echo "Error:",$e;
    }
    /*
    {hub:hubname,key:streamkey,disabled:false}
    */
```

#### Get a stream

[](#get-a-stream)

```
    try{
        $streamKey="php-sdk-test".time();
        $resp=$hub->stream($streamKey);
        print_r($resp);
    }catch(\Exception $e) {
             echo "Error:",$e;
    }
    /*
    {hub:hubname,key:streamkey,disabled:false}
    */
```

#### List streams

[](#list-streams)

```
    try{
        $streamKey="php-sdk-test".time();
        $resp=$hub->listStreams($streamKey, 1, "");
        print_r($resp);
    }catch(\Exception $e) {
             echo "Error:",$e;
    }
    /*
    keys=[streamkey] marker=
    */
```

#### List live streams

[](#list-live-streams)

```
    try{
        $streamKey="php-sdk-test".time();
        $resp=$hub->listLiveStreams($streamKey, 1, "");
        print_r($resp);
    }catch(\Exception $e) {
             echo "Error:",$e;
    }
    /*
    keys=[streamkey] marker=
    */
```

### Stream

[](#stream)

#### Get stream info

[](#get-stream-info)

```
    try{
        $resp = $stream->info();
    }catch(\Exception $e) {
       echo "Error:",$e;
    }
    /*
    {hub:PiliSDKTest,key:streamkey,disabled:false}
    */
```

#### Disable a stream

[](#disable-a-stream)

```
    try{
        $resp = $stream->info();
        print_r($resp);
        $stream->disable();
        $resp = $stream->info();
        print_r($resp);
    }catch(\Exception $e) {
       echo "Error:",$e;
    }
    /*
    before disable: {hub:PiliSDKTest,key:streamkey,disabled:false}
    after disable: {hub:PiliSDKTest,key:streamkey,disabled:true}
    */
```

#### Enable a stream

[](#enable-a-stream)

```
    try{
        $resp = $stream->info();
        print_r($resp);
        $stream->enable();
        $resp = $stream->info();
        print_r($resp);
    }catch(\Exception $e) {
       echo "Error:",$e;
    }
    /*
    before enable: {hub:PiliSDKTest,key:streamkey,disabled:true}
    after enable: {hub:PiliSDKTest,key:streamkey,disabled:false}
    */
```

#### Get stream live status

[](#get-stream-live-status)

```
   try{
       $status=$stream->liveStatus();
       print_r($status);
   }catch(\Exception $e) {
       echo "Error:",$e;
   }
   /*
   {StartAt:1463382400 ClientIP:172.21.1.214:52897 BPS:128854 FPS:{Audio:38 Video:23 Data:0}}
   */
```

#### Get stream history activity

[](#get-stream-history-activity)

```
    $records= $stream->historyActivity(0,0);
    print_r($records);
    /*
    [{1463382401 1463382441}]
    */
```

#### Save stream live playback

[](#save-stream-live-playback)

```
    try{
        $fname=$stream->save(0,0);
        print_r($fname);
    }catch(\Exception $e) {
        echo "Error:",$e;
    }
    /*
    recordings/z1.PiliSDKTest.streamkey/1463156847_1463157463.m3u8
    */
```

### Room

[](#room)

#### Create a room

[](#create-a-room)

```
$ak = "Tn8WCjE_6SU7q8CO3-BD-yF4R4IZbHBHeL8Q9t";
$sk = "vLZNvZDojo1F-bYOjOqQ43-NYqlKAej0e9OweInh";
$mac = new Qiniu\Pili\Mac($ak, $sk);
$client = new Qiniu\Pili\RoomClient($mac);
$resp=$client->createRoom("901","testroom");
print_r($resp);
```

#### Get a room

[](#get-a-room)

```
$ak = "Tn8WCjE_6SU7q8CO3-BD-yF4R4IZbHBHeL8Q9t";
$sk = "vLZNvZDojo1F-bYOjOqQ43-NYqlKAej0e9OweInh";
$mac = new Qiniu\Pili\Mac($ak, $sk);
$client = new Qiniu\Pili\RoomClient($mac);
$resp=$client->getRoom("testroom");
print_r($resp);
```

#### Delete a room

[](#delete-a-room)

```
$ak = "Tn8WCjE_6SU7q8CO3-BD-yF4R4IZbHBHeL8Q9t";
$sk = "vLZNvZDojo1F-bYOjOqQ43-NYqlKAej0e9OweInh";
$mac = new Qiniu\Pili\Mac($ak, $sk);
$client = new Qiniu\Pili\RoomClient($mac);
$resp=$client->deleteRoom("testroom");
print_r($resp);
```

#### Generate a room token

[](#generate-a-room-token)

```
$ak = "Tn8WCjE_6SU7q8CO3-BD-yF4R4IZbHBHeL8Q9t";
$sk = "vLZNvZDojo1F-bYOjOqQ43-NYqlKAej0e9OweInh";
$mac = new Qiniu\Pili\Mac($ak, $sk);
$client = new Qiniu\Pili\RoomClient($mac);
$resp=$client->roomToken("testroom","123",'admin',1785600000000);
print_r($resp);
```

History
-------

[](#history)

- 2.0.0

    - pili.v2
- 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

39

—

LowBetter than 85% of packages

Maintenance19

Infrequent updates — may be unmaintained

Popularity43

Moderate usage in the ecosystem

Community22

Small or concentrated contributor base

Maturity59

Maturing project, gaining track record

 Bus Factor2

2 contributors hold 50%+ of commits

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 ~279 days

Total

2

Last Release

3066d ago

### Community

Maintainers

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

---

Top Contributors

[![rwifeng](https://avatars.githubusercontent.com/u/1814146?v=4)](https://github.com/rwifeng "rwifeng (12 commits)")[![longbai](https://avatars.githubusercontent.com/u/1204301?v=4)](https://github.com/longbai "longbai (11 commits)")[![Jhuster](https://avatars.githubusercontent.com/u/9508582?v=4)](https://github.com/Jhuster "Jhuster (4 commits)")[![ankadada](https://avatars.githubusercontent.com/u/26298506?v=4)](https://github.com/ankadada "ankadada (2 commits)")[![liangchaoboy](https://avatars.githubusercontent.com/u/17689793?v=4)](https://github.com/liangchaoboy "liangchaoboy (1 commits)")[![jemygraw](https://avatars.githubusercontent.com/u/1751166?v=4)](https://github.com/jemygraw "jemygraw (1 commits)")[![wangliangliang2](https://avatars.githubusercontent.com/u/20638550?v=4)](https://github.com/wangliangliang2 "wangliangliang2 (1 commits)")[![wangtuanjie](https://avatars.githubusercontent.com/u/4090971?v=4)](https://github.com/wangtuanjie "wangtuanjie (1 commits)")

---

Tags

cloudweb servicestreamingqiniuhlsdashflvrtmppilihdlhds

###  Code Quality

TestsPHPUnit

Code StylePHP\_CodeSniffer

### Embed Badge

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

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

###  Alternatives

[pili-engineering/pili-sdk-php

Pili Streaming Cloud server-side library for PHP.

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

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

542275.0k8](/packages/aminyazdanpanah-php-ffmpeg-video-streaming)[alibabacloud/client

Alibaba Cloud Client for PHP - Use Alibaba Cloud in your PHP project

2223.5M366](/packages/alibabacloud-client)[opencoconut/coconut

Coconut is a Cloud Video Encoding Service built for developers

17482.5k2](/packages/opencoconut-coconut)[pdfcrowd/pdfcrowd

A client library for the Pdfcrowd API. It lets you convert between HTML, PDF and various image formats

631.1M1](/packages/pdfcrowd-pdfcrowd)[bitmovin/bitmovin-php

PHP-Client which enables you to seamlessly integrate the Bitmovin API into your existing projects

2058.7k](/packages/bitmovin-bitmovin-php)

PHPackages © 2026

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