FAQ about SDK for PHP

Updated at: 2025-03-27 05:52

This topic provides answers to some frequently asked questions (FAQ) about the integration and use of Alibaba Cloud SDK for PHP. This helps you correctly and efficiently use Alibaba Cloud SDK for PHP.

Prerequisites

  • PHP 5.6 or later is installed.

  • Composer is globally installed. For more information, see the "Globally" section of the Getting Started topic.

Important

The version of PHP used to install Alibaba Cloud SDK by using Composer must be earlier than or equal to the version of PHP used to run Alibaba Cloud SDK. For example, the vendor folder generated after Alibaba Cloud SDK is installed in PHP 7.2 can be used only in PHP 7.2 or later. If the vendor folder is copied to PHP 5.6, the dependency is incompatible with PHP 5.6.

Overview

Question 1: What do I do if the "PHP Fatal error: Uncaught ArgumentCountError: Too few arguments to function AlibabaCloud\Credentials\AccessKeyCredential::__construct(), 1 passed and exactly 2" error message is returned?

The possible cause is that Alibaba Cloud credentials are not properly configured, such as an AccessKey pair.

Sample error request:

$config = new Config([
    // Required. Make sure that the following environment variable is set in the code runtime environment: ALIBABA_CLOUD_ACCESS_KEY_ID. 
    "accessKeyId" => getenv("yourAccessKeyID"),
    // Required. Make sure that the following environment variable is set in the code runtime environment: ALIBABA_CLOUD_ACCESS_KEY_SECRET. 
    "accessKeySecret" => getenv("yourAccessKeySecret")
]);

Sample success request:

$config = new Config([
    // Required. Make sure that the following environment variable is set in the code runtime environment: ALIBABA_CLOUD_ACCESS_KEY_ID. 
    "accessKeyId" => getenv("ALIBABA_CLOUD_ACCESS_KEY_ID"),
    // Required. Make sure that the following environment variable is set in the code runtime environment: ALIBABA_CLOUD_ACCESS_KEY_SECRET. 
    "accessKeySecret" => getenv("ALIBABA_CLOUD_ACCESS_KEY_SECRET")
]);

Solution:

Important

Do not hard-code the AccessKey ID and AccessKey secret into your code. This poses security risks.

Note

getenv("ALIBABA_CLOUD_ACCESS_KEY_ID")

and getenv("ALIBABA_CLOUD_ACCESS_KEY_SECRET") specify that the AccessKey ID and AccessKey secret are obtained from the ALIBABA_CLOUD_ACCESS_KEY_ID and ALIBABA_CLOUD_ACCESS_KEY_SECRET environment variables.

  • Check whether the ALIBABA_CLOUD_ACCESS_KEY_ID and ALIBABA_CLOUD_ACCESS_KEY_SECRET environment variables are configured.

  • On Linux or macOS, run the following commands on a terminal. On Windows, choose Start > Run or press Win+R, enter cmd in the dialog box that appears, click OK or press Enter, and then run the following commands in the command prompt window. If a valid AccessKey pair is returned, the environment variables are properly configured. If no AccessKey pair is returned or an error is reported, configure the environment variables again. For more information, see the "Configure an access credential" section of the Integrate Alibaba Cloud SDK V2.0 for Python topic.

Windows
Linux or macOS
echo %ALIBABA_CLOUD_ACCESS_KEY_ID%
echo %ALIBABA_CLOUD_ACCESS_KEY_SECRET%
echo $ALIBABA_CLOUD_ACCESS_KEY_ID
echo $ALIBABA_CLOUD_ACCESS_KEY_SECRET

Question 2: What do I do if the "cURL error 60: SSL certificate problem: unable to get local issuer certificate" or "curl error 28 while downloading https://repo.packagist.org/packages.json: SSL connection timeout" error message is returned when I call an API operation?

Possible causes:

  1. Network issues: The on-premises network is unstable or the SSL connection is blocked by the firewall.

  2. Proxy issues: Access to external resources fails due to incorrect proxy configurations.

  3. SSL certificate issues: The connection times out because some SSL certificates are not trusted by the operating system of the on-premises machine.

Solutions:

  1. Make sure that you can access the Internet over stable connections.

  2. Configure PHP Composer to use a proxy:

    composer config -g -- unset http-proxy
    composer config -g -- unset https-proxy
    composer config -g http-proxy http://your-proxy:port
    composer config -g https-proxy https://your-proxy:port
  3. Download an SSL certificate issued by a trusted certificate authority (CA):

    1. Download an SSL certificate from a trusted CA. For example, you can download an SSL certificate from Mozilla. For more information, see CA certificates extracted from Mozilla.

    2. Configure the path of the SSL certificate for PHP. Search for the curl.cainfo parameter in the php.ini file, set the value of this parameter to the absolute path of the CA certificate, and then remove the semicolon (;) before the parameter.

    3. Restart the PHP service.

  4. Optional. Configure your operating system to trust the self-signed certificate. If the connection issue is caused by the self-signed certificate, allow PHP Composer to ignore SSL authentication. However, we recommend that you do not use this method in the production environment.

    composer config --global -- disable-ssl
    Important

    This command temporarily disables SSL authentication. To ensure system security, you must run the composer config --global -- enable-ssl command in the subsequent operations to enable SSL authentication again.

Question 3: What do I do if the "PHP Fatal error: Class 'Darabonba\OpenApi\Models\Config' not found" error message is returned?

The autoload feature of Composer is not enabled. Solution:

When Composer downloads a dependency, Composer generates the vendor folder that contains the autoload.php file. Add the require_once statement to your code.

require_once(<autoload.php file in the vendor folder>)

Question 4: What do I do if the "PHP Fatal error: Uncaught exception 'GuzzleHttp\Exception\RequestException' with message 'cURL error 3" error message is returned?

The region ID or endpoint is not properly configured. Solution:

Check whether the region that you specify supports the service that you want to call. In this example, Short Message Service (SMS) is used. You can go to the homepage of SMS in OpenAPI Explorer and view the endpoints of SMS in various regions.image

Question 5: What do I do if the "Could not fetch [repository], please review your configured GitHub OAuth token" error message is returned?

The GitHub OAuth token provided to Composer is incorrect or has expired. Solution:

Important

You do not need to configure a GitHub OAuth token for the Alibaba Cloud SDK package.

  • If your Composer is not installed from the official website and no GitHub OAuth token is required to access a private repository, remove the auth.json file from the Composer directory.

  • If a GitHub OAuth token is required to access a private repository, follow the instructions in Composer to update the token.

Question 6: What do I do if the "cURL error 28: Resolving timed out after 5000 milliseconds (see https://curl.haxx.se/libcurl/c/libcurl-errors.html) for https://dysmsapi.aliyuncs.com" error message is returned when I call an API operation?

An API call timeout may be caused by multiple factors. The following section describes the common causes and the corresponding solutions.

Network connection issues

Cause: The request cannot reach the server because the network connection between the client and server fails or the network is unstable.

Solutions:

  • Run the ping [www.example.com/192.168.x.x] or curl -Is https://xxx.xxx.xx command to check the network connectivity. If the network connection fails, check whether a blocking policy is configured in the firewall or router. If the network is unstable, we recommend that you change the network environment.

  • Specify a longer timeout period. For more information, see Configure a timeout period. For example, you can configure the connection timeout parameter to specify a longer connection timeout period. Sample code:

// Configure the timeout period for connection requests by using runtime parameters. The timeout period takes effect only for requests that use RuntimeOptions.
$runtimeOptions = new RuntimeOptions();
$runtimeOptions->connectTimeout = $connectionTimeoutMillis;

Long processing time of the API request

Cause: The time for processing the API request exceeds the specified read timeout period.

Solution: Specify a longer read timeout period for the API response. For more information, see Configure a timeout period. For example, you can configure the read timeout parameter to extend the read timeout period. Sample code:

// Configure the timeout period for read requests by using runtime parameters. The timeout period takes effect only for requests that use RuntimeOptions.
$runtimeOptions = new RuntimeOptions();
$runtimeOptions->readTimeout = $readTimeoutMillis;

Question 7: What do I do if the "alibabacloud/tea[3.0.0,3.2.01 require ext-curl*-> it is missing from your system. Install or enable PHP's curl extension,100e..." error message is returned?

The cURL plugin for PHP is not installed. Solution:

Ubuntu and Debian

sudo apt-get install php-curl

CentOS, Fedora, and RHEL

sudo yum install php-curl

Question 8: How do I resolve a network exception that occurs when I install Alibaba Cloud SDK for PHP?

Configure an image source for Composer. In the Chinese mainland, you may need to use an image source for Composer to speed up downloads. This can be implemented by modifying the global configuration of Composer:

  • Alibaba Cloud images for PHP Composer:

    composer config -g repo.packagist composer https://mirrors.aliyun.com/composer/
  • Tsinghua University TUNA Association images for PHP Composer:

    composer config -g repo.packagist composer https://mirrors.tuna.tsinghua.edu.cn/composer/

Question 9: What do I do if the "[Composer\Downloader\TransportException], failed to download the file due to HTTP/1.1 404 Not Found" or "“your requirements could not be resolved to an installable set of packages" error is thrown by the composer require command?

image

Possible causes:

  • The image source, such an Alibaba Cloud image, is not synchronized with the latest package. As a result, some required files are absent.

  • The URL of the image source may have changed, or the path is incorrect.

Solutions:

  1. Make sure that the image source is correct.

    1. Run the following command to check the image source configured for PHP Composer:

      composer config -g --list
    2. Alibaba Cloud images for PHP Composer: https://mirrors.aliyun.com/composer/

      composer config -g repo.packagist composer https://mirrors.aliyun.com/composer/
    3. Tsinghua University TUNA Association images for PHP Composer: https://mirrors.tuna.tsinghua.edu.cn/composer/

      composer config -g repo.packagist composer https://mirrors.tuna.tsinghua.edu.cn/composer/
  2. Temporarily disable the image source and use the Composer image repository. Modify or delete the repositories configuration in the composer.json file, or run the composer config --unset repos.url command.

    # Use the Composer image repository. 
    composer config -g repo.packagist composer https://packagist.org
  3. Check the network connection. Unstable network connections may cause file download errors. Switch to another network environment or use a VPN.

  4. Optional. When you run the command, if the Warning: This development build of composer is over 60 days old. It is recommended to update it by running "/usr/bin/composer self-update" to get the latest version error message is returned, your PHP Composer is outdated. We recommend that you update Composer to the latest version and run Composer again.

    # Update Composer to the latest version. 
    composer self-update
    # Use the composer.phar file to run the latest version. 
    composer self-update --1
  5. If a Composer warning is output when you run the command, support for Composer 1 will be disabled. Optional. To ensure compatibility and security, we recommend that you update Composer to version 2.X.

    composer self-update --2
    Important

    Check whether the dependency package of the project supports Composer 2.x. Update the project code and configurations if necessary.

  6. If the Content-Length error is thrown during the download process, data downloading may be interrupted. The received data is different from the expected data.

    1. Clear the Composer cache and run the command again to install Composer.

      PowerShell
      Shell
      # Delete the .composer directory.
      Remove-Item -Recurse -Force $HOME\.composer
      
      # Delete all content in the /tmp directory.
      Remove-Item -Recurse -Force C:\tmp\*
      rm -rf ~/.composer/ && rm -rf /tmp/*
    2. Unstable network connections may interrupt data downloading. You can run the command multiple times to ensure that Composer is installed.

    3. Make sure that network connections are stable and download the file during off-peak hours.

Question 10: What do I do if the "Could not delete D:\www\touming_keyword_api\vendor\composer\tmp-7fd77eb46d69640d6040743642007957:This can be due to an antivirus or the Windows Search Indexer locking the file while they are analyzed." error is thrown by PHP Composer?

image

Possible causes:

When Composer attempts to install the dependency, the temporary file cannot be deleted because the file is locked by some anti-virus software or Windows Search Indexer.

Solutions:

  1. Check whether you have sufficient permissions on the Windows operating system. If not, Composer may fail to create or modify the required files.

    1. Run all Composer commands as the administrator to prevent permission issues.

    2. Make sure that Composer has read and write permissions on the required files and directories.

  2. Make sure that the package version is available, clear the cache, and re-install the dependency.

    1. Query the available versions of the package. Sample command:

      composer show alibabacloud/ecs-20140526 --all
    2. Clear the Composer cache and re-install the dependency:

      composer clear-cache
  3. Check whether Windows Search Indexer is running as expected. This service may index files, which locks the files. To stop this service, perform the following steps:

    1. Press the Win and R keys to open the Run program.

    2. Enter services.msc and press the Enter keys.

    3. Find the Windows Search service, right-click the service, and then select Stop.

    4. After you stop Windows Search, install the Composer dependency again.

  4. Unlock the files or create a directory for installing the dependency.

    1. To unlock the files, run the following commands as the administrator:

      1. Right-click Command Prompt or PowerShell and select Run as administrator.

      2. Run the following command to delete the locked directory:

        rmdir /S /Q "D:\www\touming_keyword_api\vendor\composer\tmp-7fd77eb46d69640d6040743642007957"
      3. Make sure that the file is not locked by a program, such as anti-virus software or Windows Search Indexer. You can temporarily disable your anti-virus software and run the Composer command.

    2. Create a directory for installing the dependency. In the directory, perform the following Composer operations:

      mkdir D:\new_directory
      cd D:\new_directory
      composer require alibabacloud/ecs-20140526 6.0.1
  5. If the 404 error is thrown during the installation process, switch to another image source and perform the installation again.

    composer config -g repo.packagist composer https://packagist.org

Question 11: What do I do if the "cURL error 61" error is thrown by the composer require alibabacloud/dysmsapi-20170525 command?image

Possible causes:

  1. Composer cache issues: The local cache is damaged or incomplete.

  2. Image source issues: The image source is unstable or unavailable.

  3. Network issues: The network connections are unstable or blocked by the firewall.

  4. Composer version issues: Composer is outdated.

  5. Environment configuration issues: The environment variables or Composer configuration file contain errors.

Solutions:

  1. Check the network connection.

    1. Run the following command to test the network connectivity:

      curl -I https://mirrors.aliyun.com/composer/p2/alibabacloud/dysmsapi-20170525.json
    2. Make sure that the firewall does block access from curl to external resources.

    3. Switch to another network or network environment, such as from the office network to a personal network.

  2. Configure Composer to use the Composer image repository.

    composer config -g --list
    composer config -g repo.packagist composer https://packagist.org
  3. Delete the Composer package, re-install Composer, and clear the Composer cache.

    1. Delete the on-premises cache directory:

      rm -rf ~/.composer
    2. Clear the Composer cache:

      composer clear-cache
  4. If the issue persists, check the detailed Composer logs:

    composer install --verbose

Technical support

The solutions to the preceding issues can help you better use Alibaba Cloud SDKs. If you encounter other issues when you use Alibaba Cloud SDKs, contact us in the following way:

  • Submit a ticket.

  • If you have questions or feedback, contact Alibaba Cloud technical support in the DingTalk group (ID: 60965016010).

  • On this page (1, M)
  • Prerequisites
  • Overview
  • Question 1: What do I do if the "PHP Fatal error: Uncaught ArgumentCountError: Too few arguments to function AlibabaCloud\Credentials\AccessKeyCredential::__construct(), 1 passed and exactly 2" error message is returned?
  • Question 2: What do I do if the "cURL error 60: SSL certificate problem: unable to get local issuer certificate" or "curl error 28 while downloading https://repo.packagist.org/packages.json: SSL connection timeout" error message is returned when I call an API operation?
  • Question 3: What do I do if the "PHP Fatal error: Class 'Darabonba\OpenApi\Models\Config' not found" error message is returned?
  • Question 4: What do I do if the "PHP Fatal error: Uncaught exception 'GuzzleHttp\Exception\RequestException' with message 'cURL error 3" error message is returned?
  • Question 5: What do I do if the "Could not fetch [repository], please review your configured GitHub OAuth token" error message is returned?
  • Question 6: What do I do if the "cURL error 28: Resolving timed out after 5000 milliseconds (see https://curl.haxx.se/libcurl/c/libcurl-errors.html) for https://dysmsapi.aliyuncs.com" error message is returned when I call an API operation?
  • Question 7: What do I do if the "alibabacloud/tea[3.0.0,3.2.01 require ext-curl*-> it is missing from your system. Install or enable PHP's curl extension,100e..." error message is returned?
  • Question 8: How do I resolve a network exception that occurs when I install Alibaba Cloud SDK for PHP?
  • Question 9: What do I do if the "[Composer\Downloader\TransportException], failed to download the file due to HTTP/1.1 404 Not Found" or "“your requirements could not be resolved to an installable set of packages" error is thrown by the composer require command?
  • Question 10: What do I do if the "Could not delete D:\www\touming_keyword_api\vendor\composer\tmp-7fd77eb46d69640d6040743642007957:This can be due to an antivirus or the Windows Search Indexer locking the file while they are analyzed." error is thrown by PHP Composer?
  • Question 11: What do I do if the "cURL error 61" error is thrown by the composer require alibabacloud/dysmsapi-20170525 command?
  • Technical support
Feedback
phone Contact Us

Chat now with Alibaba Cloud Customer Service to assist you in finding the right products and services to meet your needs.

alicare alicarealicarealicare