PHP code example of sony / cdn-purge-control-php

1. Go to this page and download the library: Download sony/cdn-purge-control-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/ */

    

sony / cdn-purge-control-php example snippets





// Require the Composer autoloader.
ge\CdnType;

$config = array(
    'cloudfront' => array(
            'distribution_id' => 'your cloudfront distribution id'
        ),
    'limelight' => array(
            'shortname' => 'your limelight api shortname'
            'publish_url' => 'your limelight publish url'
        )
);
$credential = array(
    'cloudfront' => array(
            'key' => 'aws iam account access key id',
            'secret' => 'aws iam account secret access key'
        ),
    'limelight' => array(
            'username' => 'limelight account username',
            'shared_key' => 'limelight account shared key'
        )
);

try {
    // Make a purge request against AWS cloudfront
    $cfClient = CdnPurgeFactory::build(CdnType::CLOUDFRONT, $credential, $config);
    $cfRequestId = $client->createPurgeRequest(array(
        '/my-path-1',
        '/my-path-2'
    ));

    // Make a purge request against Limelight
    $llClient = CdnPurgeFactory::build(CdnType::LIMELIGHT, $credential, $config);
    $llRequestId = $client->createPurgeRequest(array(
        'http://my-limelight-domain/my-path-1',
        '/my-path-2'
    ));

} catch (CdnPurge\CdnClientException $e) {
    echo "An error occurred: " . $e->getMessage();
}


// Get the purge status
try {
    $client->getPurgeStatus($requestId);
    // 'InProgress' or 'Complete'
} catch (CdnPurge\CdnClientException $e) {
    echo "There was an error getting purge status.\n";
}
bash
# Install Composer
curl -sS https://getcomposer.org/installer | php