Initialization

EIP

  • API Reference
    • API function release records
    • API Service Domain Name
    • API Specifications
    • Appendix 1
    • Bandwidth Package Related Interfaces
      • Adjust the bandwidth of the bandwidth package
      • Create bandwidth package
      • Query bandwidth package details
      • Query bandwidth package list information of users
      • Release bandwidth package
      • Update the automatic release time of the bandwidth package
      • Update the name of the bandwidth package
    • DDoS Basic Protection Related Interfaces
      • Modify DDoS basic protection threshold
      • Query DDoS Basic Protection Attack Records
      • Query DDoS basic protection list
    • EIP Related Interfaces
      • Apply for EIP
      • Bind EIP
      • Disable EIP direct
      • EIP bandwidth scaling
      • EIP renewal has been enabled
      • Enable EIP direct
      • Query EIP list in bucket trash
      • Query EIP list
      • Release EIP
      • Release EIPs in the bucket trash
      • Renew EIP
      • Restore EIPs in the bucket trash
      • Selective release of EIP
      • Unbind EIP
      • Unsubscribe prepaid EIP
      • Update EIP Release Protection Switch
    • Error code
    • General Description
    • Inquiry Related
      • Bandwidth package price inquiry
      • EIP Inquiry
      • EIPGROUP Inquiry
      • Shared Traffic Package Inquiry
    • Interface Overview
    • Overview
    • Prerequisites for use
    • Shared Bandwidth Related Interfaces
      • Bandwidth scaling up for EIPGROUP
      • Create EIPGROUP
      • EIPGROUP IP count upgrade
      • EIPGROUP release
      • EIPGROUP renewal
      • EIPGROUP update
      • Migrate EIP from EIPGROUP
      • Migrate EIP into EIPGROUP
      • Query EIPGROUP details
      • Query the EIPGROUP list
      • Unsubscribe prepaid EIPGROUP
    • Shared Traffic Package Related Interfaces
      • Create a shared traffic package
      • Query shared traffic package details
      • Query shared traffic package list
    • TBSP Related Interfaces
      • Add Protection IP Allow List
      • Add Protocol Blocking
      • Add Region Blocking
      • Bind Protection Object
      • Close Protection IP Cleaning
      • Create TBSP
      • Delete Protection IP Allow List
      • Delete Protection Object
      • Delete Protocol Blocking
      • Delete Region Blocking
      • Modify Protection IP Cleaning Threshold
      • Modify Protection IP Protection Level
      • Open Protection IP Cleaning
      • Query Protection IP Allow List
      • Query Protection IP Cleaning Threshold List
      • Query Protocol Blocking List
      • Query Region Blocking List
      • Query TBSP Details
      • Query TBSP List
      • TBSP Capacity dilatation
      • TBSP renew
  • FAQs
    • Billing class
    • Configuration
    • Consultation
    • Security class
  • Function Release Records
  • Operation guide
    • Address pool
    • Bandwidth package
      • Bandwidth scale-up package
      • Cross-border acceleration package
    • Certification
    • DDoS standard protection
    • EIP Instance
      • Create instance
      • EIP Direct Connect
      • IPv6 Termination
      • Manage Alarms
      • Operation Instance
      • Shift Charge
      • View monitoring
    • EIP Self-Service Diagnostics
      • EIP Instance Diagnosis
    • EIPGROUP
      • Bind cloud resources
      • Manage Shared Bandwidth
      • Purchase Shared Bandwidth
      • View monitoring
    • High Defense EIP
    • Identity and access management
    • Recycle bin
    • Shared traffic package
      • Purchase Shared Traffic Package
      • View Shared Traffic Package
    • Tag Management
    • Traffic Burst Service Package
      • Instance management
      • Monitor alarm
      • Protection Configuration
    • Unblocking Center
  • Product Description
    • Application scenarios
    • Product advantages
    • Product Introduction
    • Usage restrictions
  • Product pricing
    • Bandwidth Package Billing
    • EIP Instance Billing
    • EIPGROUP Billing
    • Shared Traffic Package Billing
    • TBSP Billing
  • SDK
    • GO-SDK
      • DDoS Instance
      • EIP Instance
      • EipBp Instance
      • EIPGROUP Instance
      • EipTp Instance
      • Exception handling
      • Initialization
      • Install the SDK Package
      • Overview
    • Java-SDK
      • EIP Instance
      • EipBP Instance
      • EIPGROUP Instance
      • EipTp Instance
      • Exception handling
      • Initialization
      • Install the SDK Package
      • Overview
      • Version history
    • PHP-SDK
      • EIP Instance
      • EipBP Instance
      • EIPGROUP Instance
      • Exception handling
      • Initialization
      • Install the SDK Package
      • Overview
      • Version history
    • Python-SDK
      • EIP Instance
      • EipBP Instance
      • EIPGROUP Instance
      • EipTp Instance
      • Exception handling
      • Initialization
      • Install the SDK Package
      • Overview
      • Version history
  • Service Level Agreement (SLA)
    • EIP Service Level Agreement SLA
    • TBSP Service Level Agreement SLA
  • Typical Practices
    • Bring Your Own Overseas Public IP Address to the Cloud
    • IPv6 Public Network Access
    • Save Public Network Costs
    • TCP Port 25 Restriction Description
All documents
menu
No results found, please re-enter

EIP

  • API Reference
    • API function release records
    • API Service Domain Name
    • API Specifications
    • Appendix 1
    • Bandwidth Package Related Interfaces
      • Adjust the bandwidth of the bandwidth package
      • Create bandwidth package
      • Query bandwidth package details
      • Query bandwidth package list information of users
      • Release bandwidth package
      • Update the automatic release time of the bandwidth package
      • Update the name of the bandwidth package
    • DDoS Basic Protection Related Interfaces
      • Modify DDoS basic protection threshold
      • Query DDoS Basic Protection Attack Records
      • Query DDoS basic protection list
    • EIP Related Interfaces
      • Apply for EIP
      • Bind EIP
      • Disable EIP direct
      • EIP bandwidth scaling
      • EIP renewal has been enabled
      • Enable EIP direct
      • Query EIP list in bucket trash
      • Query EIP list
      • Release EIP
      • Release EIPs in the bucket trash
      • Renew EIP
      • Restore EIPs in the bucket trash
      • Selective release of EIP
      • Unbind EIP
      • Unsubscribe prepaid EIP
      • Update EIP Release Protection Switch
    • Error code
    • General Description
    • Inquiry Related
      • Bandwidth package price inquiry
      • EIP Inquiry
      • EIPGROUP Inquiry
      • Shared Traffic Package Inquiry
    • Interface Overview
    • Overview
    • Prerequisites for use
    • Shared Bandwidth Related Interfaces
      • Bandwidth scaling up for EIPGROUP
      • Create EIPGROUP
      • EIPGROUP IP count upgrade
      • EIPGROUP release
      • EIPGROUP renewal
      • EIPGROUP update
      • Migrate EIP from EIPGROUP
      • Migrate EIP into EIPGROUP
      • Query EIPGROUP details
      • Query the EIPGROUP list
      • Unsubscribe prepaid EIPGROUP
    • Shared Traffic Package Related Interfaces
      • Create a shared traffic package
      • Query shared traffic package details
      • Query shared traffic package list
    • TBSP Related Interfaces
      • Add Protection IP Allow List
      • Add Protocol Blocking
      • Add Region Blocking
      • Bind Protection Object
      • Close Protection IP Cleaning
      • Create TBSP
      • Delete Protection IP Allow List
      • Delete Protection Object
      • Delete Protocol Blocking
      • Delete Region Blocking
      • Modify Protection IP Cleaning Threshold
      • Modify Protection IP Protection Level
      • Open Protection IP Cleaning
      • Query Protection IP Allow List
      • Query Protection IP Cleaning Threshold List
      • Query Protocol Blocking List
      • Query Region Blocking List
      • Query TBSP Details
      • Query TBSP List
      • TBSP Capacity dilatation
      • TBSP renew
  • FAQs
    • Billing class
    • Configuration
    • Consultation
    • Security class
  • Function Release Records
  • Operation guide
    • Address pool
    • Bandwidth package
      • Bandwidth scale-up package
      • Cross-border acceleration package
    • Certification
    • DDoS standard protection
    • EIP Instance
      • Create instance
      • EIP Direct Connect
      • IPv6 Termination
      • Manage Alarms
      • Operation Instance
      • Shift Charge
      • View monitoring
    • EIP Self-Service Diagnostics
      • EIP Instance Diagnosis
    • EIPGROUP
      • Bind cloud resources
      • Manage Shared Bandwidth
      • Purchase Shared Bandwidth
      • View monitoring
    • High Defense EIP
    • Identity and access management
    • Recycle bin
    • Shared traffic package
      • Purchase Shared Traffic Package
      • View Shared Traffic Package
    • Tag Management
    • Traffic Burst Service Package
      • Instance management
      • Monitor alarm
      • Protection Configuration
    • Unblocking Center
  • Product Description
    • Application scenarios
    • Product advantages
    • Product Introduction
    • Usage restrictions
  • Product pricing
    • Bandwidth Package Billing
    • EIP Instance Billing
    • EIPGROUP Billing
    • Shared Traffic Package Billing
    • TBSP Billing
  • SDK
    • GO-SDK
      • DDoS Instance
      • EIP Instance
      • EipBp Instance
      • EIPGROUP Instance
      • EipTp Instance
      • Exception handling
      • Initialization
      • Install the SDK Package
      • Overview
    • Java-SDK
      • EIP Instance
      • EipBP Instance
      • EIPGROUP Instance
      • EipTp Instance
      • Exception handling
      • Initialization
      • Install the SDK Package
      • Overview
      • Version history
    • PHP-SDK
      • EIP Instance
      • EipBP Instance
      • EIPGROUP Instance
      • Exception handling
      • Initialization
      • Install the SDK Package
      • Overview
      • Version history
    • Python-SDK
      • EIP Instance
      • EipBP Instance
      • EIPGROUP Instance
      • EipTp Instance
      • Exception handling
      • Initialization
      • Install the SDK Package
      • Overview
      • Version history
  • Service Level Agreement (SLA)
    • EIP Service Level Agreement SLA
    • TBSP Service Level Agreement SLA
  • Typical Practices
    • Bring Your Own Overseas Public IP Address to the Cloud
    • IPv6 Public Network Access
    • Save Public Network Costs
    • TCP Port 25 Restriction Description
  • Document center
  • arrow
  • EIP
  • arrow
  • SDK
  • arrow
  • PHP-SDK
  • arrow
  • Initialization
Table of contents on this page
  • Confirm Endpoint
  • Retrieve access key
  • Create EipClient/EipGroupClient/EipBpClient
  • Create EipClient/EipGroupClient/EipBpClient with AK/SK
  • Create EipClient/EipGroupClient/EipBpClient with STS
  • Configure HTTPS protocol to access EIP/EipGroup/EipBp
  • Access EIP/EipGroup/EipBp via custom domain name (CNAME)
  • Configure EipClient/EipGroupClient/EipBpClient
  • Set custom parameters

Initialization

Updated at:2025-10-16

Confirm Endpoint

Before configuring the endpoint for SDK usage, please refer toAPI Service Domain Name in API Reference to understand endpoint-related concepts. Baidu AI Cloud currently supports multiple regions. Please refer toRegion Selection Guide. Corresponding information:

Access region Endpoint
Beijing eip.bj.baidubce.com
Guangzhou eip.gz.baidubce.com
Suzhou eip.su.baidubce.com
Hong Kong eip.hkg.baidubce.com
Wuhan eip.fwh.baidubce.com
Baoding eip.bd.baidubce.com

Retrieve access key

To use Baidu AI Cloud EIP, users need a valid AK (Access Key ID) and SK (Secret Access Key) for signature certification. AK/SK are system-assigned strings used to identify users and perform signature certification for EIP. Your AK/SK information can be obtained and understood through the following steps: Register a Baidu AI Cloud account Create AK/SK

Create EipClient/EipGroupClient/EipBpClient

EipClient/EipGroupClient serves as the PHP client for the Eip/EIPGROUP/EipBp services, providing developers with methods to interact with these PHP client services.

Before creating EipClient/EipGroupClient/EipBpClient, a configuration file must be created for the purpose of configuration. In the example below, this file is named YourConf.php, with the following configuration details:

PHP
1//Report all PHP errors
2error_reporting(-1);
3define('__EIP_CLIENT_ROOT', dirname(__DIR__));
4 //Set EipClient Access Key ID, Secret Access Key and ENDPOINT
5$EIP_TEST_CONFIG =
6    array(
7        'credentials' => array(
8            'accessKeyId' => 'your ak',
9            'secretAccessKey' => 'your sk',
10            'sessionToken' => 'your session token'
11        ),
12        'endpoint' => 'http://eip.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, accessKeyId corresponds to “Access Key ID” in the console. secretAccessKey corresponds to “Access Key Secret” in the console. For the method to retrieve them, refer to the Guide - Manage ACCESSKEY.
  2. If users need to specify their own domain name, they can upload the ENDPOINT parameters, which must be defined with the domain name of the specified region. For example, if the service is located in Beijing, the endpoint will be http://eip.bj.baidubce.com.
  3. If STS authentication is not used, stsEndpoint and sessionToken can be left empty or deleted.

Create EipClient/EipGroupClient/EipBpClient with AK/SK

Users can refer to the following code to create an EipClient to access BOS with AK/SK:

PHP
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\Eip\EipClient;
9use BaiduBce\Services\EipGroup\EipGroupClient;
10 //Call parameters from configuration file
11global $EIP_TEST_CONFIG;
12 // Create EipClient
13$eipClient = new EipClient($EIP_TEST_CONFIG);
14 // Create EipGroupClient
15$eipGroupClient = new EipGroupClient($EIP_TEST_CONFIG);
16 // Create EipBpClient
17 $eipBpClient = new Create EipBpClient($EIP_TEST_CONFIG);

Create EipClient/EipGroupClient/EipBpClient with STS

Request STS Token

EIP allows temporary third-party access authorization using the STS mechanism. STS (Security Token Service) is a temporary authorization service offered by Baidu AI Cloud. With STS, you can issue access credentials with customizable validity periods and permissions to third-party users. These users can then utilize the credentials to directly call Baidu AI Cloud APIs or SDKs to access cloud resources.

To access EIP 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 EipClient with STS Token

Upon successful application of the STS, it is possible to configure the STS token in EipClient/EipGroupClient. Users may refer to the following code to create a new EipClient/EipGroupClient:

  1. First, configure the STS endpoint. Below is an example of STS configuration:
PHP
1$EIP_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. The sample code of StsClient is as follows:
PHP
1//Create StsClient
2$client = new StsClient($EIP_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;

Note: The acl here refers to the user-defined access control list, and its syntax can be referred to in Access Control.

  1. Enter the retrived accessKeyID/secretAccessKey/sessionToken in the configuration file YourConf.php, and create EipClient.
PHP
1$EIP_TEST_CONFIG =
2    array(
3        'credentials' => array(
4            'accessKeyId' => 'your ak',
5            'secretAccessKey' => 'your sk',
6            'sessionToken' => 'your session token'
7        ),
8        'endpoint' => 'http://eip.bj.baidubce.com',
9    );
10 // Create EipClient
11    $eipClient = new EipClient($EIP_TEST_CONFIG);
12 // Create EipGroupClient
13    $eipGroupClient = new EipGroupClient($EIP_TEST_CONFIG);
14 // Create EipBpClient
15    $eipBpClient = new EipBpClient($EIP_TEST_CONFIG);

Note: Currently, when configuring a client with STS, regardless of where the corresponding EIP service endpoint is located, the endpoint must be set to http://sts.bj.baidubce.com.

Configure HTTPS protocol to access EIP/EipGroup/EipBp

EIP supports HTTPS transport protocol. Users can use HTTPS to access the EIP/EipGroup service in the EIP PHP SDK in the following two ways:

  • Specify HTTPS in the endpoint:
PHP
1$EIP_CONFIG =
2  array(
3      'credentials' => array(
4          'ak' => 'your-ak',
5          'sk' => 'your-sk',
6      ),
7      'endpoint' => 'https://eip.bj.baidubce.com',
8  );
9  $eipClient = new EipClient($EIP_CONFIG);
10  $eipGroupClient = new EipGroupClient($EIP_CONFIG);
11  $eipBpClient = new EipBpClient($EIP_CONFIG);
  • Set the HTTPS protocol by specifying https in protocol:
Plain Text
1$EIP_CONFIG =
2  array(
3      'credentials' => array(
4          'ak' => 'your-ak',
5          'sk' => 'your-sk',
6      ),
7      'endpoint' => 'eip.bj.baidubce.com',
8      'protocol' => 'https',
9  );
10  $eipClient = new EipClient($EIP_CONFIG);
11  $eipGroupClient = new EipGroupClient($EIP_CONFIG);
12  $eipBpClient = new EipBpClient($EIP_CONFIG);

Note: If you specify the protocol parameter while specifying the scheme of the endpoint, the endpoint shall prevail.

PHP
1$EIP_CONFIG =
2  array(
3      'credentials' => array(
4          'ak' => 'your-ak',
5          'sk' => 'your-sk',
6      ),
7      'endpoint' => 'http://eip.bj.baidubce.com',
8      'protocol' => 'https',
9  );
10 $eipClient = new EipClient($EIP_CONFIG); //Accesses EIP via HTTP
11 $eipGroupClient = new EipGroupClient($EIP_CONFIG); //Accesses eipgroup via HTTP
12 $eipBpClient = new EipBpClient($EIP_CONFIG); //Accesses eipBp via HTTP

Access EIP/EipGroup/EipBp via custom domain name (CNAME)

Users can access the EIP service using a custom domain name in the EIP PHP SDK in the following way:

Specify the custom domain name in the endpoint and set the custom field to true to indicate the use of a custom domain name:

PHP
1$EIP_CONFIG =
2  array(
3      'credentials' => array(
4          'ak' => 'your-ak',
5          'sk' => 'your-sk',
6      ),
7      'endpoint' => 'http://custom-domain.com',
8      'custom' => true,
9  );
10  $eipClient = new EipClient($EIP_CONFIG);
11  $eipGroupClient = new EipGroupClient($EIP_CONFIG);
12  $eipBpClient = new EipBpClient($EIP_CONFIG);

Configure EipClient/EipGroupClient/EipBpClient

Set custom parameters

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 EipClient construction. Reference code is as follows:

PHP
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 EipClient with custom configuration
16        $customizedEipClient = new EipClient($customizedConfig);
17 //Create EipGroupClient with custom configuration
18        $customizedEipGroupClient = new EipGroupClient($customizedConfig);
19 //Create EipGroupClient with custom configuration
20        $customizedEipBpClient = new EipBpClient($customizedConfig);
21    }

The parameter description is as follows:

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 Receive buffer size 10 1024 1024

Previous
Exception handling
Next
Install the SDK Package