Baidu AI Cloud
中国站

百度智能云

CDN

CdnClient

Being the client of the CDN service, CdnClient provides a series of methods for developers to interact with the CDN service.

Create CdnClient

Access to CDN via AK/SK

Access CDN via AK/SK, and users can create a CDN Client by reference to the following codes:

Before creating a CdnClient, you need to configure the CdnClient by creating a configuration file named YourConf.php with specific content as follows:

	 //Report all PHP errors 
	 error_reporting(-1); 
	 define('CDN_CLIENT_ROOT', dirname(__DIR__)); 
	 //Set Access Key ID, Secret Access Key and ENDPOINT of CdnClient 
	$g_CDN_TEST_CONFIG =
	 array( 
	    'credentials' => array( 
	        'accessKeyId' => 'your ak', 
	        'secretAccessKey' => 'your sk', 
	    ), 
	    'endpoint' => 'http://cdn.baidubce.com', 
	 ); 
	 //Set the format and level of the log 
	 $__handler = new \Monolog\Handler\StreamHandler(STDERR, \Monolog\Logger::DEBUG); 
	 $__handler->setFormatter( 
	 new \Monolog\Formatter\LineFormatter(null, null, false, true) 
	 ); 
	 \BaiduBce\Log\LogFactory::setInstance( 
	 new \BaiduBce\Log\MonoLogFactory(array($__handler)) 
	 ); 
	 \BaiduBce\Log\LogFactory::setLogLevel(\Psr\Log\LogLevel::DEBUG); 

In the above code, the variables AK and SK are assigned to user by the system, and they are strings used to identify the user and perform signature verification for accessing CDN. Among them, ak corresponds to the “Access Key ID” in the console, and SK corresponds to “Access Key Secret” in the console. Please refer to Get AK/SK.

Create CdnClient

After completing the above configuration, refer to the following code to create CdnClient.

	 include 'BaiduBce.phar'; 
	 require 'YourConf.php'; 
	 use BaiduBce\BceClientConfigOptions; 
	 use BaiduBce\Util\Time; 
	 use BaiduBce\Util\MimeTypes; 
	 use BaiduBce\Http\HttpHeaders; 
	 use BaiduBce\Services\Cdn\CdnClient; 
	 //Call parameters in the configuration file 
	 global $g_CDN_TEST_CONFIG; 
	 //Create a CdnClient 
	 $client = new CdnClient($g_CDN_TEST_CONFIG);
Previous
Getting Started
Next
Acceleration Domain Name Management