PHP code example of vin7ent / pili-sdk-php.v2

1. Go to this page and download the library: Download vin7ent/pili-sdk-php.v2 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/ */

    

vin7ent / pili-sdk-php.v2 example snippets








    // 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=$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=
    */

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

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

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

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

    // 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);

    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}
    */

    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}
    */

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

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

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

    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}
    */

    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}
    */

   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}}
   */

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

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

$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);

$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);

$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);

$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);
bash
# Install Composer
curl -sS https://getcomposer.org/installer | php
bash
php composer.phar 
bash
$ git clone https://github.com/pili-engineering/pili-sdk-php.v2.git