Initialization

BLB BLB

  • API Reference
    • Access control
    • API Service Domain Name
    • Appendix
    • Application BLB Interface
      • Application BLB Instance Related Interfaces
      • Application BLB Listener Related Interfaces
      • Application BLB Security Group Related Interfaces
      • Application BLB Server Group Related Interfaces
    • Application IPv6 BLB Interface
      • Application IPv6 BLB Instance Related Interfaces
      • Application IPv6 BLB Listener Related Interfaces
      • Application IPv6 BLB Security Group Related Interfaces
      • Application IPv6 BLB Server Group Related Interfaces
    • BLB Order Related Interfaces
      • BLB - Resize
      • BLB Charge Shift - Cancel Prepay to Postpay
      • BLB Charge Shift - Postpay to Prepay
      • BLB Charge Shift - Prepay to Postpay
      • BLB Inquiry
      • BLB Unsubscribe Interface
    • Document Update Records
    • Error code
    • Interface Specifications
    • Introduction
    • Load Balancer Dedicated Cluster LBDC Interface
      • LBDC Instance Related Interfaces
    • Service Publishing Point Interface
      • Service Publishing Point Related Interfaces
    • Standard BLB Interface
      • Standard BLB Instance Related Interfaces
      • Standard BLB Listener Related Interfaces
      • Standard BLB Real Server Related Interfaces
      • Standard BLB Security Group Related Interfaces
    • Standard IPv6 BLB Interface
      • Standard IPv6 BLB Related Interfaces
  • FAQs
    • Billing Problems
    • Common Questions Overview
    • Configuration-related questions
    • Fault-related questions
    • General Problems
    • Load Balancer Dedicated Cluster Related Issues
    • Performance-related questions
    • Security Problems
  • Function Release Records
  • Operation guide
    • Access control
    • Access Logs
    • Application BLB instance
    • Application IPv6 Instance
    • BLB metric description
    • Certification
    • Custom configuration
    • Extended domain name
    • General-purpose BLB instance
      • Creating BLB Ordinary Instance
      • Managing BLB Ordinary Instance
    • General-purpose IPv6 BLB instance
    • Identity and access management
    • IP Group Usage Guide
    • Load Balance Dedicated Cluster
    • Load Balancer Frontend and Backend Protocol Correspondence
    • Recording Access Logs Using VPC Flow Logs
    • Service Release Point
    • Tag Management
  • Product Description
    • Application scenarios
    • Basic Architecture
    • Basic concepts
    • Performance Specification Description
    • Product advantages
    • Product features
    • Product Introduction
    • Usage restrictions
  • Product pricing
    • Load Balancer Dedicated Cluster Billing
    • Load Balancer Instance Billing
  • Quick Start
  • SDK
    • GO-SDK
      • Application BLB Instance
      • Initialization
      • Install
      • IPv6 BLB Instance
      • Load Balance Dedicated Cluster (LBDC)
      • Ordinary BLB Instance
      • Overview
      • Service Release Point
      • Version Change Records
    • Java-SDK
      • Application BLB instance
      • General-purpose BLB instance
      • Initialization
      • Install the SDK Package
      • IPv6 BLB Instance
      • Load Balance Dedicated Cluster (LBDC)
      • Overview
      • Service Release Point
      • Version Update Description
    • PHP-SDK
      • Initialization
      • Install
      • Ordinary BLB Instance
      • Overview
    • Python-SDK
      • Application BLB Instance
      • Initialization
      • Install
      • IPv6 BLB Instance
      • Load Balance Dedicated Cluster (LBDC)
      • Ordinary BLB Instance
      • Overview
      • Service Release Point
      • Version Update Description
  • Service Level Agreement (SLA)
    • Description of Baidu AI Cloud Load Balancer Trusted Cloud certification service availability
    • LBDC Service Level Agreement SLA
    • BLB Service Level Agreement (V2.0)
  • Typical Practices
    • BLB Selection Guide
    • Health Check Exception Troubleshooting
    • Implementing BLB Association with Listeners, Real Servers, Security Groups, etc. via Terraform
    • Implementing Multi-Site Hosting via Application BLB
    • Load Balancer Security Protection Strategy
    • Managing BLB via Terraform
    • Obtaining Client Information via Application BLB Instance
    • Using IP Group Function to Mount Real Servers Across VPCs in Different Regions
    • Using IP Group Function to Mount Real Servers Across VPCs in the Same Region
All documents
menu
No results found, please re-enter

BLB BLB

  • API Reference
    • Access control
    • API Service Domain Name
    • Appendix
    • Application BLB Interface
      • Application BLB Instance Related Interfaces
      • Application BLB Listener Related Interfaces
      • Application BLB Security Group Related Interfaces
      • Application BLB Server Group Related Interfaces
    • Application IPv6 BLB Interface
      • Application IPv6 BLB Instance Related Interfaces
      • Application IPv6 BLB Listener Related Interfaces
      • Application IPv6 BLB Security Group Related Interfaces
      • Application IPv6 BLB Server Group Related Interfaces
    • BLB Order Related Interfaces
      • BLB - Resize
      • BLB Charge Shift - Cancel Prepay to Postpay
      • BLB Charge Shift - Postpay to Prepay
      • BLB Charge Shift - Prepay to Postpay
      • BLB Inquiry
      • BLB Unsubscribe Interface
    • Document Update Records
    • Error code
    • Interface Specifications
    • Introduction
    • Load Balancer Dedicated Cluster LBDC Interface
      • LBDC Instance Related Interfaces
    • Service Publishing Point Interface
      • Service Publishing Point Related Interfaces
    • Standard BLB Interface
      • Standard BLB Instance Related Interfaces
      • Standard BLB Listener Related Interfaces
      • Standard BLB Real Server Related Interfaces
      • Standard BLB Security Group Related Interfaces
    • Standard IPv6 BLB Interface
      • Standard IPv6 BLB Related Interfaces
  • FAQs
    • Billing Problems
    • Common Questions Overview
    • Configuration-related questions
    • Fault-related questions
    • General Problems
    • Load Balancer Dedicated Cluster Related Issues
    • Performance-related questions
    • Security Problems
  • Function Release Records
  • Operation guide
    • Access control
    • Access Logs
    • Application BLB instance
    • Application IPv6 Instance
    • BLB metric description
    • Certification
    • Custom configuration
    • Extended domain name
    • General-purpose BLB instance
      • Creating BLB Ordinary Instance
      • Managing BLB Ordinary Instance
    • General-purpose IPv6 BLB instance
    • Identity and access management
    • IP Group Usage Guide
    • Load Balance Dedicated Cluster
    • Load Balancer Frontend and Backend Protocol Correspondence
    • Recording Access Logs Using VPC Flow Logs
    • Service Release Point
    • Tag Management
  • Product Description
    • Application scenarios
    • Basic Architecture
    • Basic concepts
    • Performance Specification Description
    • Product advantages
    • Product features
    • Product Introduction
    • Usage restrictions
  • Product pricing
    • Load Balancer Dedicated Cluster Billing
    • Load Balancer Instance Billing
  • Quick Start
  • SDK
    • GO-SDK
      • Application BLB Instance
      • Initialization
      • Install
      • IPv6 BLB Instance
      • Load Balance Dedicated Cluster (LBDC)
      • Ordinary BLB Instance
      • Overview
      • Service Release Point
      • Version Change Records
    • Java-SDK
      • Application BLB instance
      • General-purpose BLB instance
      • Initialization
      • Install the SDK Package
      • IPv6 BLB Instance
      • Load Balance Dedicated Cluster (LBDC)
      • Overview
      • Service Release Point
      • Version Update Description
    • PHP-SDK
      • Initialization
      • Install
      • Ordinary BLB Instance
      • Overview
    • Python-SDK
      • Application BLB Instance
      • Initialization
      • Install
      • IPv6 BLB Instance
      • Load Balance Dedicated Cluster (LBDC)
      • Ordinary BLB Instance
      • Overview
      • Service Release Point
      • Version Update Description
  • Service Level Agreement (SLA)
    • Description of Baidu AI Cloud Load Balancer Trusted Cloud certification service availability
    • LBDC Service Level Agreement SLA
    • BLB Service Level Agreement (V2.0)
  • Typical Practices
    • BLB Selection Guide
    • Health Check Exception Troubleshooting
    • Implementing BLB Association with Listeners, Real Servers, Security Groups, etc. via Terraform
    • Implementing Multi-Site Hosting via Application BLB
    • Load Balancer Security Protection Strategy
    • Managing BLB via Terraform
    • Obtaining Client Information via Application BLB Instance
    • Using IP Group Function to Mount Real Servers Across VPCs in Different Regions
    • Using IP Group Function to Mount Real Servers Across VPCs in the Same Region
  • Document center
  • arrow
  • BLBBLB
  • arrow
  • SDK
  • arrow
  • PHP-SDK
  • arrow
  • Initialization
Table of contents on this page
  • Confirm Endpoint
  • Create a BlbClient
  • Create a BlbClient with AK/SK
  • Create BlbClient with STS
  • Configure BlbClient

Initialization

Updated at:2025-10-16

Confirm Endpoint

Before configuring the Endpoint for SDK usage, please refer to the developer guide section on BLB Access Domain Name to understand Endpoint-related concepts. Baidu AI Cloud currently supports multiple regions. Please refer to Region Selection Guide.

Currently, supported regions include "Beijing," "Guangzhou," "Suzhou," "Hong Kong," "Wuhan," "Baoding," "Shanghai," and "Singapore.\

The corresponding information for the service domain name:

Access region Endpoint
bj blb.bj.baidubce.com
gz blb.gz.baidubce.com
su blb.su.baidubce.com
hkg blb.hkg.baidubce.com
fwh blb.fwh.baidubce.com
bd blb.bd.baidubce.com
fsh blb.fsh.baidubce.com
sin blb.sin.baidubce.com

Create a BlbClient

BlbClient acts as the client for BLB services, offering developers a variety of methods to interact with BLB service features.

Before creating BlbClient, a configuration file must be created to configure BlbClient. Below, this configuration file is named YourConf.php, with the following specific configuration information:

Plain Text
1//Report all PHP errors
2error_reporting(-1);
3define('__BLB_CLIENT_ROOT', dirname(__DIR__));
4 //Set BlbClient的Access Key ID, Secret Access Key and ENDPOINT
5$BLB_TEST_CONFIG =
6    array(
7        'credentials' => array(
8            'accessKeyId' => 'your ak',
9            'secretAccessKey' => 'your sk',
10            'sessionToken' => 'your session token'
11        ),
12        'endpoint' => 'http://blb.bj.baidubce.com',
13        'stsEndpoint' => 'http://sts.bj.baidubce.com',
14    );
15 //Set the log format and level
16$__handler = new \Monolog\Handler\StreamHandler(STDERR, \Monolog\Logger::DEBUG);
17$__handler->setFormatter(
18    new \Monolog\Formatter\LineFormatter(null, null, false, true)
19);
20\BaiduBce\Log\LogFactory::setInstance(
21    new \BaiduBce\Log\MonoLogFactory(array($__handler))
22);
23\BaiduBce\Log\LogFactory::setLogLevel(\Psr\Log\LogLevel::DEBUG);

Note:

  1. In the code above, ACCESS_KEY_ID corresponds to “Access Key ID” in the console. SECRET_ACCESS_KEY corresponds to “Access Key Secret” in the console. For the method to retrieve them, refer to the Guide - Retrieve ACCESSKEY.
  2. If users wish to use a custom domain name, they must upload the ENDPOINT parameters, which need to align with the domain name of the specified region. For instance, if the service is hosted in Beijing, the endpoint would be http://blb.bj.baidubce.com.
  3. If STS authentication is not being utilized, the stsEndpoint and sessionToken fields can remain empty or be removed.

Create a BlbClient with AK/SK

Users can refer to the following code to create a BlbClient to access BLB with AK/SK:

Plain Text
1//Use PHP SDK with a custom configuration file
2include 'BaiduBce.phar';
3require 'YourConf.php';
4use BaiduBce\BceClientConfigOptions;
5use BaiduBce\Util\Time;
6use BaiduBce\Util\MimeTypes;
7use BaiduBce\Http\HttpHeaders;
8use BaiduBce\Services\Blb\BlbClient;
9 //Call parameters from configuration file
10global $BLB_TEST_CONFIG;
11 //Create BlbClient
12$client = new BlbClient($BLB_TEST_CONFIG);

Create BlbClient with STS

Request STS Token BLB enables temporary third-party access authorization through the STS mechanism. STS (Security Token Service) is a temporary authorization service provided by Baidu AI Cloud. Through STS, you can issue access credentials with customized validity periods and permissions to third-party users. Third-party users can use these credentials to directly call Baidu AI Cloud APIs or SDKs to access cloud resources.

To access BLB via STS, users must first request a certification string through the STS client. For instructions on obtaining STS credentials, refer to Baidu AI Cloud STS Usage Guide.

Create BLBClient with STS Token After requesting the STS token, configure it in the BlbClient. The following codes demonstrate how to initialize the client:

  1. First configure the STS endpoint. STS configuration example is as follows:
Plain Text
1$BLB_TEST_CONFIG =
2    array(
3        'credentials' => array(
4            'accessKeyId' => 'your ak',
5            'secretAccessKey' => 'your sk',
6        ),
7	'stsEndpoint' => 'http://sts.bj.baidubce.com',
8    );
  1. Example code for StsClient is as follows:
Plain Text
1//Create StsClient
2$client = new StsClient($BLB_TEST_CONFIG);
3$request =
4    array(
5 'acl' => $aclArray, //User-defined acl
6 'durationSeconds' => 43200, //STS credential validity period
7    );
8$response = $client->getSessionToken($request);
9$accessKeyID= $response->accessKeyId;
10$secretAccessKey= $response->secretAccessKey;
11$sessionToken = $response->sessionToken;
  1. Enter the retrieved accessKeyID/secretAccessKey/sessionToken into the configuration file YourConf.php, and then create a BlbClient.
Plain Text
1$BLB_TEST_CONFIG =
2    array(
3        'credentials' => array(
4            'accessKeyId' => 'your ak',
5            'secretAccessKey' => 'your sk',
6            'sessionToken' => 'your session token'
7        ),
8        'endpoint' => 'http://blb.bj.baidubce.com',
9    );
10 //Create BlbClient
11    $client = new BlbClient($BLB_TEST_CONFIG);

Note: When using STS to configure a client, the endpoint must always be http://sts.bj.baidubce.com, irrespective of the location of the corresponding BLB service.

Configure BlbClient

PHP SDK sets some default parameters in \BaiduBce\Bce.php. To modify these values, users may create custom parameter configuration functions with reference to this file, and pass them during BlbClient construction. Reference code is as follows:

Plain Text
1public function CustomizedConfig() {
2        $customizedConfig = array(
3            BceClientConfigOptions::PROTOCOL => 'http',
4            BceClientConfigOptions::REGION => 'bj',
5            BceClientConfigOptions::CONNECTION_TIMEOUT_IN_MILLIS => 120 * 1000,
6            BceClientConfigOptions::SOCKET_TIMEOUT_IN_MILLIS => 300 * 1000,
7            BceClientConfigOptions::SEND_BUF_SIZE => 5 * 1024 * 1024,
8            BceClientConfigOptions::RECV_BUF_SIZE => 5 * 1024 * 1024,
9            BceClientConfigOptions::CREDENTIALS => array(
10                'ak' => 'your-access-key-id',
11                'sk' => 'your-secret-access-key',
12            ),
13            'endpoint' => 'your-endpoint',
14        );
15 //Create BLBClient with custom configuration
16        $customizedClient = new BlbClient($customizedConfig);
17 //Call methods via custom configuration
18        $options = array(BlbOptions::CONFIG=>$customizedConfig);
19        $this->client->listBlbs($options);
20    }

Parameter description

Parameters Description Default value
PROTOCOL Protocol http
REGION Region bj
CONNECTION_TIMEOUT_IN_MILLIS Request timeout duration (unit: millisecond) 50 * 1000
SOCKET_TIMEOUT_IN_MILLIS Timeout for socket data transmission (unit: ms) 0 (infinite waiting. if a non-zero value is set, file size and network speed shall be evaluated; otherwise, uploading large files may cause timeout.)
SEND_BUF_SIZE Send buffer size 1024 * 1024
RECV_BUF_SIZE Protocol http
PROTOCOL Receive buffer size 10 1024 1024

Previous
Java-SDK
Next
Install