FAQ

更新时间:
复制 MD 格式

This document answers common questions about using the PHP SDK to help you develop more efficiently.

Environment check

  • Make sure that the PHP environment is correctly installed and that the PHP version is 5.6 or later.

  • Globally install Composer on your system.

Important

The PHP version used to install the SDK with Composer must be the same as or earlier than the PHP version at runtime. For example, if you install the SDK in a PHP 7.2 environment, the generated vendor directory can be used only with PHP 7.2 or later. If you copy it to a PHP 5.6 environment, dependency version incompatibility issues occur.

Problems

Problem 1: Issues with passing AccessKey parameters

Symptom: An error is reported when the code runs. If the error message contains the following information, it indicates that the Alibaba Cloud credentials (AccessKey) are not set correctly.

  • V2.0 SDK: AlibabaCloud\Tea\Exception\TeaUnableRetryError: code: 400, AccessKeyId is mandatory for this action.

  • V1.0 SDK: Fatal error: Uncaught AlibabaCloud\Client\Exception\ClientException: AccessKey ID cannot be empty in XXX.

Solution:

  1. Run the following commands to check whether the `ALIBABA_CLOUD_ACCESS_KEY_ID` and `ALIBABA_CLOUD_ACCESS_KEY_SECRET` environment variables are configured:

    Linux/macOS

    echo $ALIBABA_CLOUD_ACCESS_KEY_ID
    echo $ALIBABA_CLOUD_ACCESS_KEY_SECRET

    Windows

    echo %ALIBABA_CLOUD_ACCESS_KEY_ID%
    echo %ALIBABA_CLOUD_ACCESS_KEY_SECRET%

    If the correct AccessKey is returned, the configuration is successful. If the returned value is empty or incorrect, you can try to set the environment variables again. For more information, see Configure environment variables on Linux, macOS, and Windows systems.

  2. Check the code for errors related to the AccessKey.

    Common error example:

    $config = new Config([
        "accessKeyId" => getenv("yourAccessKeyID"),
        "accessKeySecret" => getenv("yourAccessKeySecret")
    ]);

    Correct example:

    $config = new Config([
        "accessKeyId" => getenv("ALIBABA_CLOUD_ACCESS_KEY_ID"),
        "accessKeySecret" => getenv("ALIBABA_CLOUD_ACCESS_KEY_SECRET")
    ]);
    Note

    getenv("ALIBABA_CLOUD_ACCESS_KEY_ID")

    and `getenv()` retrieves the values of `ALIBABA_CLOUD_ACCESS_KEY_ID` and `ALIBABA_CLOUD_ACCESS_KEY_SECRET` from the environment variables.

    Important

    Do not hard-code your AccessKey in plaintext in your production code. This practice poses security risks.

Problem 2: An error message "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" is reported when you call an OpenAPI.

Causes

  1. Network connectivity issues: The on-premises network is unstable, or a firewall is blocking the SSL connection.

  2. Proxy configuration issues: The proxy is not correctly configured, which prevents access to external resources.

  3. SSL certificate issues: The local system does not trust some SSL certificates, which causes connection timeouts.

Solutions

  1. Check your network connectivity. Make sure that you can access the Internet and that the network connection is stable.

  2. Configure 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 a trusted CA certificate:

    1. Download a trusted CA certificate, such as the Mozilla CA Certificate Store.

    2. Configure the SSL certificate path for PHP. In the php.ini file, search for `curl.cainfo`, set its value to the absolute path of the CA certificate, and then remove the comment symbol (;) from the beginning of the configuration item.

    3. Restart the PHP service.

  4. Trust a self-signed certificate (optional). If the connection issue is caused by a self-signed certificate, you can allow Composer to ignore SSL validation. This is not recommended for production environments.

    composer config --global -- disable-ssl
    Important

    This operation temporarily disables SSL validation. Make sure to run the command composer config --global --enable-ssl later to re-enable it and ensure system security.

Problem 3: A "PHP Fatal error: Class 'Darabonba\OpenApi\Models\Config' not found" error is reported at runtime.

This error occurs because the Composer autoload feature is not enabled. Solution:

When Composer downloads dependencies, it generates a `vendor` directory that contains an `autoload.php` file. You can add a require_once statement to your application code.

require_once(<path to the autoload.php file in the vendor directory>)

Problem 4: A "PHP Fatal error: Uncaught exception 'GuzzleHttp\Exception\RequestException' with message 'cURL error 3'" error is reported at runtime.

This error occurs because of an incorrect RegionId or Endpoint. Solution:

Make sure that the region you select supports the service you are calling. You can find the product's endpoint on the product homepage in the OpenAPI Developer Portal. For example, for Short Message Service, log on to the OpenAPI Portal. In the top navigation bar, select Short Message Service. On the Short Message Service overview page, click the Service Area List tab. View the Region ID (such as cn-beijing, cn-hangzhou, or cn-shanghai) and Service Endpoint (which is dysmsapi.aliyuncs.com for regions in the Chinese mainland and dysmsapi.ap-southeast-1.aliyuncs.com for regions outside China) for each region. Make sure that the RegionId and Endpoint in your code are consistent with this list.

Problem 5: A "Could not fetch [repository], please review your configured GitHub OAuth token" error is reported at runtime.

This error occurs because the GitHub credentials provided to Composer are incorrect or have expired. Solution:

Important

Alibaba Cloud SDK packages do not require GitHub credentials.

  • If you installed Composer from an unofficial source and do not need GitHub credentials to access private repositories, you can delete the `auth.json` file in the Composer directory.

  • If you need GitHub credentials to access private repositories, you can refresh the token as prompted by Composer.

Problem 6: An API call times out and reports the error "cURL error 28: Resolving timed out after 5000 milliseconds (see https://curl.haxx.se/libcurl/c/libcurl-errors.html) for https://dysmsapi.aliyuncs.com".

Timeouts can be caused by multiple factors. The following sections describe common causes and their solutions:

Network connectivity issues

Description: The request cannot reach the destination server because the network between the client and the server is disconnected or unstable.

Solution:

Use the ping or curl command to test the connectivity between your local host and the cloud product endpoint. For example, if a call to the SendSms operation times out, you can use ping dysmsapi.aliyuncs.com or curl -v https://dysmsapi.aliyuncs.com to test the connectivity.

  • If the command times out or does not return a response, check whether your local firewall or router has a blocking policy.

  • If the command returns a response, you can set a reasonable timeout period to prevent request failures due to improper configuration. For more information, see Timeout configuration. The following code provides an example:

// Set the timeout in runtime parameters. This is valid only for requests that use this runtime parameter instance.
$runtimeOptions = new RuntimeOptions();
$runtimeOptions->connectTimeout = $connectionTimeoutMillis;

Long API processing time

Description: The time that the destination API takes to process the request exceeds the configured read timeout period.

Solution: You can configure the read timeout period to accommodate a longer API response time. For more information, see Timeout configuration. For example, you can configure the read timeout parameter to extend the read timeout period for the current request. The following code provides an example:

// Set the timeout in runtime parameters. This is valid only for requests that use this runtime parameter instance.
$runtimeOptions = new RuntimeOptions();
$runtimeOptions->readTimeout = $readTimeoutMillis;

Problem 7: An "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 is reported at runtime.

This error occurs because the curl extension for PHP is missing. Solution:

For Ubuntu/Debian systems:

sudo apt-get install php-curl

For CentOS/Fedora/RHEL systems:

sudo yum install php-curl

Problem 8: Network exceptions occur when you install the PHP SDK.

Configure a Composer traffic mirror source: In the Chinese mainland, you may need to configure Composer to use a traffic mirror source in the Chinese mainland to speed up downloads due to network issues. You can modify the global configuration of Composer:

  • Alibaba Cloud Composer full mirror.

    composer config -g repo.packagist composer https://mirrors.aliyun.com/composer/
  • Tsinghua Composer full mirror.

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

Problem 9: When you run the composer require command, an error message "[Composer\Downloader\TransportException], The file could not be downloaded (HTTP/1.1 404 Not Found)" or "your requirements could not be resolved to an installable set of packages" is reported.

[root@hecs-x-large-2-win-20210204102325 rcw.zhiyuechuanbo.com]# composer require alibabacloud/ocr-api-20210707 3.1.2
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.
Do not run Composer as root/super user! See https://getcomposer.org/root for details
Warning from https://mirrors.aliyun.com/composer: Support for Composer 1 will be shutdown on August 1st 2025. You should upgrade to Composer 2. See https://blog.packagist.com/shutting-down-packagist-org-support-for-composer-1-x/
[Composer\Downloader\TransportException]
The "https://mirrors.aliyun.com/composer/p/provider-2013%24a2b47ec1a1bb999e53d88aff50728aebbd3d68225c74aab1ff5f071bac42f5b7.json" file could not be downloaded (HTTP/1.1 404 Not Found)

Possible causes

  • The traffic mirror source that you are using, such as the Alibaba Cloud mirror, may not have synchronized the latest package information in time. This causes some files to be missing.

  • The URL of the traffic mirror source may have changed, or the path may be incorrect.

Solutions

  1. Check and make sure that you are using the correct traffic mirror source.

    1. Run the following command to view the currently configured Composer traffic mirror source:

      composer config -g --list
    2. Alibaba Cloud Composer full mirror: https://mirrors.aliyun.com/composer/

      composer config -g repo.packagist composer https://mirrors.aliyun.com/composer/
    3. Tsinghua Composer full mirror: https://mirrors.tuna.tsinghua.edu.cn/composer/

      composer config -g repo.packagist composer https://mirrors.tuna.tsinghua.edu.cn/composer/
  2. You can temporarily disable the traffic mirror source and use the official central repository directly. To do this, modify or delete the repositories configuration in composer.json, or run the command composer config --unset repos.url.

    # Use the official Composer repository.
    composer config -g repo.packagist composer https://packagist.org
  3. Check your network connectivity. An unstable network may prevent files from being downloaded correctly. You can try switching to a different network environment or using a VPN.

  4. If a message is displayed when you run the command indicating that the Composer version is too old (`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.`), you can update to the latest version (optional).

    # Update Composer to the latest version.
    composer self-update
    # Use composer.phar to run the latest version.
    composer self-update --1
  5. If a Composer warning is displayed when you run the command, it indicates that support for Composer 1 will be discontinued. For better compatibility and security, you can upgrade to version 2.x (optional).

    composer self-update --2
    Important

    Check whether the packages that your project depends on support Composer 2.x. You may need to update the project code and configuration.

  6. If a Content-Length error occurs during the download, it is usually because the data download was interrupted, and the actual data received does not match the expected value.

    1. You can clear the Composer cache and run the installation command again.

      # Delete the .composer directory
      Remove-Item -Recurse -Force $HOME\.composer
      # Delete all content in the C:\tmp directory
      Remove-Item -Recurse -Force C:\tmp\*
      rm -rf ~/.composer/ && rm -rf /tmp/*
    2. Network fluctuations may cause download interruptions. You can run the installation command multiple times.

    3. Check your network stability. Make sure that the network connection is stable and avoid downloading during peak hours.

Problem 10: An error "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" is reported when you run Composer.

Possible causes

When Composer tries to install dependencies, it cannot delete temporary files. This may be because antivirus software or the Windows Search Indexer has locked the file.

Solutions

  1. Check permissions. On a Windows system, Composer may fail to create or modify required files due to insufficient permissions.

    1. Make sure that all Composer commands are run in administrator mode to avoid permission issues.

    2. Confirm that the files and directories required by Composer have read and write permissions.

  2. You can check the availability of the package version, clear the cache, and reinstall.

    1. Check the available versions of the required package. For example:

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

      composer clear-cache
  3. Check whether the Windows Search service is running. This service may index files, causing them to be locked. To stop this service, perform the following steps:

    1. Press Win + R to open the Run dialog box.

    2. Enter services.msc and press Enter.

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

    4. After you stop the service, try to install the Composer dependencies again.

  4. Unlock the file or create a new directory for installation.

    1. You can unlock the file by running the command line as an administrator:

      1. Right-click CMD 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 no program, such as antivirus software or the Windows Search Indexer, is locking the file. You can try to temporarily disable the antivirus software and run the Composer command again.

    2. Create a new directory for installation. You can create a new directory and perform Composer operations in it:

      mkdir D:\new_directory
      cd D:\new_directory
      composer require alibabacloud/ecs-20140526 6.0.1
  5. If a 404 error occurs during installation, you can change the traffic mirror source and try installing again.

    composer config -g repo.packagist composer https://packagist.org
D:\Appserv\PHPTutorial\WWW\changheyuedu>composer require alibabacloud/dysmsapi-20170525 2.0.8
./composer.json has been updated
Running composer update alibabacloud/dysmsapi-20170525
Loading composer repositories with package information
https://mirrors.aliyun.com/composer could not be fully loaded (curl error 61 while downloading https://mirrors.aliyun.com/composer/p2/alibabacloud/dysmsapi-20170525.json: Error while processing content unencoding: Unknown failure within decompression software.), package information was loaded from the local cache and may be out of date
Installation failed, reverting ./composer.json and ./composer.lock to their original content.
  [Composer\Downloader\TransportException]
  curl error 61 while downloading https://mirrors.aliyun.com/composer/p2/alibabacloud/dysmsapi-20170525.json: Error w
  hile processing content unencoding: Unknown failure within decompression software.

Problem 11: A "cURL error 61" is reported when you run composer require alibabacloud/dysmsapi-20170525.

Possible causes

  1. Composer cache issue: The local cache is corrupted or incomplete.

  2. Traffic mirror source issue: The traffic mirror source is unstable or unavailable.

  3. Network issue: The network connection is unstable or blocked by a firewall.

  4. Composer version issue: An outdated version of Composer is used.

  5. Environment configuration issue: The environment variables or Composer configuration file is abnormal.

Solutions

  1. Check your network connectivity.

    1. Run the following command to test whether the network is normal:

      curl -I https://mirrors.aliyun.com/composer/p2/alibabacloud/dysmsapi-20170525.json
    2. Check the firewall settings to make sure that the firewall is not blocking curl from accessing external resources.

    3. Try using a different network. You can switch the network environment, for example, from a corporate network to a personal network.

  2. You can check the Composer configuration and use the official central repository directly.

    composer config -g --list
    composer config -g repo.packagist composer https://packagist.org
  3. You can delete the installed Composer package, reinstall it, and clear the Composer cache.

    1. Delete the local cache directory:

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

      composer clear-cache
  4. If the error persists, you can check the detailed Composer logs:

    composer install --verbose

Question 12: When you runcomposer to install the Alibaba Cloud SDK package, the following error is reported: "Your requirements could not be resolved to an installable set of packages.".

This error can occur for various reasons. The following examples can help you resolve the error.

Example 1

Error message:

Your requirements could not be resolved to an installable set of packages.
Problem 1
 - Root composer.json requires alibabacloud/cloudauth-20190307 3.4.1, found alibabacloud/cloudauth-20190307[dev-master, 1.0.0, ..., 1.0.7, 2.0.0, ..., 2.9.1, 3.0.0, ..., 3.3.0] but it does not match the constraint.
Installation failed, reverting ./composer.json and ./composer.lock to their original content.

Possible causes:

  1. The specified version number, such as 3.4.1, may not exist or may not have been released.

  2. The Composer traffic mirror source that you are using has not been synchronized with the latest version of the package.

  3. A network issue prevents the package from being pulled correctly.

Solutions:

  • Run the following command to view all available versions of the package:

    composer show alibabacloud/XXXXXX --all

    You can modify the version in the composer.json file to an available version, and then run composer update to reinstall.

  • You can switch the Composer traffic mirror source.

    • Run the following command to switch to the official Packagist traffic mirror source:

      composer config -g repo.packagist composer https://repo.packagist.org
    • Switch to the accelerated traffic mirror source provided by Alibaba Cloud in the Chinese mainland:

      composer config -g repo.packagist composer https://mirrors.aliyun.com/composer/

    After switching, you can clear the cache and reinstall:

    composer clear-cache
    composer install

  • Check whether your network connection is normal and try using a stable network environment. If the installation still fails, you can try to manually download the package file in .zip or .tar.gz format and install it using a local path:

    composer require alibabacloud/XXXXXX@dev --prefer-source

Example 2

Error message:

composer could not delete the root package (root/mr.appteam/version) defaulting to ... see https://getcomposer.org/root-version
Running composer update alibabacloud/cloudauth-20190307
Loading composer repositories with package information
Updating dependencies
Your requirements could not be resolved to an installable set of packages.
  Problem 1
    - Root composer.json requires alibabacloud/cloudauth-20190307 3.9.2 -> satisfiable by alibabacloud/cloudauth-20190307[3.9.2].
    - alibabacloud/cloudauth-20190307 3.9.2 requires alibabacloud/tea-oss-utils ^0.3.1 -> satisfiable by alibabacloud/tea-oss-utils[0.3.1].
    - alibabacloud/tea-oss-utils[0.3.0, ..., 0.3.1] require guzzlehttp/psr7 ^1.0 -> found guzzlehttp/psr7[1.0.0, ..., 1.9.1] but the package is fixed
  Use the option --with-all-dependencies (-W) to allow upgrades, downgrades and removals for packages currently locked to specific versions.
Installation failed, reverting ./composer.json and ./composer.lock to their original content.
[root@ebs-171291 mrrapp.com]#

Cause:

When you install alibabacloud/cloudauth-20190307:3.9.2, its dependency alibabacloud/tea-oss-utils:0.3.1 requires guzzlehttp/psr7 to be version `[1.0.0,...,2.0.0)`. However, the currently installed version of guzzlehttp/psr7 is fixed at `[1.0.0,..,1.9.1]`, which causes a dependency conflict.

Solutions:

  • You can force an update of the dependency version.

    composer require alibabacloud/cloudauth-20190307 3.9.2 -W
  • In the `require` section of the composer.json file, you can add a version constraint for guzzlehttp/psr7, such as "guzzlehttp/psr7": "^1.0". Then, run the following command to update the dependencies.

    composer update
  • You can delete composer.lock and run the following command to reinstall.

    composer install --prefer-source

Problem 12: An error message "cURL error 60: SSL certificate problem: unable to get local issuer certificate" is reported when you call an OpenAPI.

Causes:

  1. CA certificate package not downloaded: The system is missing a trusted CA certificate file, which prevents cURL from verifying the SSL certificate.

  2. PHP's cURL configuration does not specify a CA certificate path: The curl.cainfo or openssl.cafile parameter is not correctly configured in the php.ini file.

  3. PHP service not restarted: The PHP service was not restarted after the php.ini file was modified, so the configuration did not take effect.

Solutions:

  1. You can download a trusted CA certificate, such as the Mozilla CA Certificate Store. Save the downloaded cacert.pem file to a fixed directory.

    Important

    Make sure that the file path does not contain Chinese characters or special characters to avoid potential issues.

  2. You can configure the SSL certificate path for PHP.

    • Open the PHP configuration file php.ini. You can find the file location by running the php --ini command.

    • In the php.ini file, find curl.cainfo, set its value to the absolute path of the CA certificate, and remove the semicolon (;) from the beginning of the configuration item.

      # Example
      curl.cainfo = "D:\path\to\cacert.pem"
      openssl.cafile = "D:\path\to\cacert.pem"

      Save the file after editing.

      Note

      Replace the D:\path\to\cacert.pem path in the example with the actual absolute path of your downloaded CA certificate.

  3. Restart the PHP service.

Problem 13: Composer installation fails with the message "the package is fixed to version 1.0.3 (lock file version) or ralouphie/mimey 2.1.0 requires php ^5.4|^7.0 your php version (8.2.27) does not satisfy that requirement."

Causes

  1. Version conflicts:

    • The versions of some dependencies are locked by the composer.lock file.

    • By default, Composer does not automatically update these locked dependency packages.

    • For example, alibabacloud/cloudauth-20190307 requires version 2.0.1 of alibabacloud/openplatform-20191219, but the current locked version is 1.0.3.

  2. PHP version incompatibility:

    • You are using PHP 8.2, but some dependency packages support only PHP 5.4 to 7.x.

    • For example, ralouphie/mimey 2.1.0 supports only PHP ^5.4|^7.0, but your environment is PHP 8.2.27.

Solutions

  1. You can force an upgrade of all related dependencies:

    composer update --with-all-dependencies
    # Or the short form:
    composer update -W
    Note

    This operation recursively updates all related dependency packages, including old versions locked by `composer.lock`, to help resolve version conflicts.

  2. You can clear composer.lock and vendor/ and then reinstall. This is recommended for severe dependency confusion.

    rm composer.lock vendor/
    composer clear-cache
    composer install
    Important

    This operation removes all installed dependencies.

  3. If a dependency package does not support PHP 8, you can temporarily downgrade to an earlier version of PHP to ensure compatibility.

Problem 14: Script @php think service:discover handling the post-autoload-dump event returned with error code 255.

Causes

  • After you run `composer install` or `update`, Composer fails to execute ThinkPHP's automatic service discovery command, php think service:discover. This interrupts the entire installation process.

  • Memory overflow or other errors.

Solutions

  1. You can temporarily disable the service discovery script. To do this, modify the composer.json file in the project's root directory:

    {
        "scripts": {
            "post-autoload-dump": "@php think service:discover"
        }
    }

    Change it to:

    {
        "scripts": {
            "post-autoload-dump": "@echo Skipping 'php think service:discover'"
        }
    }

    Run composer dump-autoload again.

  2. You can increase the PHP memory limit. To do this, modify the following configuration in the php.ini file:

    memory_limit = 512M

Problem 15: Undefined property: Darabonba\OpenApi\Models\Config::$tlsMinVersion

Cause: The version of alibabacloud/darabonba-openapi is earlier than 0.2.14.

Solution: Run the following command to update alibabacloud/darabonba-openapi to version 0.2.14 or later.

composer require alibabacloud/darabonba-openapi >=0.2.14 

Technical support

The solutions to the preceding problems are intended to help you use the Alibaba Cloud SDK more easily. If you encounter other problems, you can contact us in one of the following ways:

  • Submit a ticket: Alibaba Cloud Ticket Submission page.

  • If you have related needs or feedback, you can join the DingTalk group to contact Alibaba Cloud technical support. The group number is 60965016010.