This topic provides answers to some frequently asked questions about the integration and use of Alibaba Cloud SDK for PHP to help you improve your development efficiency.
Environment check
PHP 5.6 or later is installed.
Composer is globally installed. For more information, see the "Globally" section of the Getting Started topic.
The version of PHP used to install Alibaba Cloud SDK 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.
List of problems
Question 1: How do I handle AccessKey errors?
Problem: The following error message is returned after running code. The error message indicates that the AccessKey pair is not correctly configured.
Alibaba Cloud SDK V2.0: AlibabaCloud\Tea\Exception\TeaUnableRetryError: code: 400, AccessKeyId is mandatory for this action.
Alibaba Cloud SDK V1.0: Fatal error: Uncaught AlibabaCloud\Client\Exception\ClientException: AccessKey ID cannot be empty in XXX.
Solutions:
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_SECRETWindows
echo %ALIBABA_CLOUD_ACCESS_KEY_ID% echo %ALIBABA_CLOUD_ACCESS_KEY_SECRET%If a valid AccessKey pair is returned, the environment variables are properly configured. If no AccessKey pair or an invalid AccessKey pair is returned, configure the environment variables as required. For more information, see Configure environment variables in Linux, macOS, and Windows.
Check for errors related to the AccessKey pair in the code.
Sample error request:
$config = new Config([ "accessKeyId" => getenv("yourAccessKeyID"), "accessKeySecret" => getenv("yourAccessKeySecret") ]);Sample success request:
$config = new Config([ "accessKeyId" => getenv("ALIBABA_CLOUD_ACCESS_KEY_ID"), "accessKeySecret" => getenv("ALIBABA_CLOUD_ACCESS_KEY_SECRET") ]);Notegetenv("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.
ImportantTo prevent security risks, do not write the AccessKey pair in the online code.
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:
Network issues: The on-premises network is unstable or the SSL connection is blocked by the firewall.
Proxy issues: Access to external resources fails due to incorrect proxy configurations.
SSL certificate issues: The connection times out because some SSL certificates are not trusted by the operating system of the on-premises machine.
Solutions:
Make sure that you can access the Internet over stable connections.
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:portDownload an SSL certificate issued by a trusted certificate authority (CA):
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.
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.
Restart the PHP service.
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-sslImportantThis command temporarily disables SSL authentication. To ensure system security, you must run the
composer config --global -- enable-sslcommand 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. Solutions:
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. Solutions:
Make sure that the service that you want to access is available in the selected region. 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.
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. Solutions:
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 or curl command to test the connectivity between the on-premises host and the endpoint of the cloud service. For example, run the ping dysmsapi.aliyuncs.com or curl -v https://dysmsapi.aliyuncs.com command to test the connectivity between your on-premises host and the endpoint of the SMS API.
If the command times out or does not receive a response, check for blocking policies on your on-premises firewall or routers.
If a response is returned, we recommend that you specify a proper timeout period to prevent request failures caused by improper timeout configurations. For more information, see Configure a timeout period. Sample code:
// Specify a timeout period using runtime parameters. The timeout period takes effect only on the requests that use the RuntimeOptions instance.
$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 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 plug-in for PHP is not installed. Solutions:
For Ubuntu or Debian systems:
sudo apt-get install php-curlFor CentOS, Fedora, and RHEL systems:
sudo yum install php-curlQuestion 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?

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:
Make sure that the image source is correct.
Run the following command to check the image source configured for PHP Composer:
composer config -g --listAlibaba Cloud images for
Composer:https://mirrors.aliyun.com/composer/composer config -g repo.packagist composer https://mirrors.aliyun.com/composer/Tsinghua University TUNA Association images for
Composer:https://mirrors.tuna.tsinghua.edu.cn/composer/composer config -g repo.packagist composer https://mirrors.tuna.tsinghua.edu.cn/composer/
Temporarily disable the image source and use the Composer image repository. Modify or delete the
repositoriesconfiguration in thecomposer.jsonfile, or run thecomposer config --unset repos.urlcommand.# Use the Composer image repository. composer config -g repo.packagist composer https://packagist.orgCheck the network connection. Unstable network connections may cause file download errors. Switch to another network environment or use a VPN.
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 versionerror 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 --1If a
Composerwarning is output when you run the command, support forComposer 1will be disabled. Optional. To ensure compatibility and security, we recommend that you update Composer to version 2.X.composer self-update --2ImportantCheck whether the dependency package of the project supports Composer 2.x. Update the project code and configurations if necessary.
If the
Content-Lengtherror is thrown during the download process, data downloading may be interrupted. The received data is different from the expected data.Clear the Composer cache and run the command again to install Composer.
# 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/*Unstable network connections may interrupt data downloading. You can run the command multiple times to ensure that Composer is installed.
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?

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:
Check whether you have sufficient permissions on the Windows operating system. If not, Composer may fail to create or modify the required files.
Run all Composer commands as the administrator to prevent permission issues.
Make sure that Composer has read and write permissions on the required files and directories.
Make sure that the package version is available, clear the cache, and re-install the dependency.
Query the available versions of the package. Sample command:
composer show alibabacloud/ecs-20140526 --allClear the Composer cache and re-install the dependency:
composer clear-cache
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:
Press the
Win and Rkeys to open the Run program.Enter
services.mscand press theEnterkeys.Find the Windows Search service, right-click the service, and then select Stop.
After you stop Windows Search, install the Composer dependency again.
Unlock the files or create a directory for installing the dependency.
To unlock the files, run the following commands as the administrator:
Right-click Command Prompt or PowerShell and select Run as administrator.
Run the following command to delete the locked directory:
rmdir /S /Q "D:\www\touming_keyword_api\vendor\composer\tmp-7fd77eb46d69640d6040743642007957"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.
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
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?
Possible causes:
Composer cache issues: The local cache is damaged or incomplete.
Image source issues: The image source is unstable or unavailable.
Network issues: The network connections are unstable or blocked by the firewall.
Composer version issues: Composer is outdated.
Environment configuration issues: The environment variables or Composer configuration file contain errors.
Solutions:
Check the network connection.
Run the following command to test the network connectivity:
curl -I https://mirrors.aliyun.com/composer/p2/alibabacloud/dysmsapi-20170525.jsonYou can check the firewall settings to ensure that the firewall is not blocking
curlfrom accessing external resources.Switch to another network or network environment, such as from the office network to a personal network.
Configure Composer to use the Composer image repository.
composer config -g --list composer config -g repo.packagist composer https://packagist.orgDelete the Composer package, re-install Composer, and clear the Composer cache.
Delete the on-premises cache directory:
rm -rf ~/.composerClear the Composer cache:
composer clear-cache
If the issue persists, check the detailed Composer logs:
composer install --verbose
Question 12: The "Your requirements could not be resolved to an installable set of packages." error occurs when you use composer to install an Alibaba Cloud SDK package.
This error can occur for various reasons. The following examples can help you resolve this 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:
The specified version number, such as
3.4.1, may not exist or may not be released.The Composer mirror source that you are using is not synchronized with the latest version of the package.
A network issue prevents the package from being pulled correctly.
Solution:
Run the following command to query all available package versions:
composer show alibabacloud/XXXXXX --allSpecify an available version in the
composer.jsonfile, and run thecomposer updatecommand to update to the latest version.Switch to another
Composerimage source.Run the following command to switch to a Packagist image source:
composer config -g repo.packagist composer https://repo.packagist.orgSwitch to the Alibaba Cloud accelerated image source in the Chinese mainland:
composer config -g repo.packagist composer https://mirrors.aliyun.com/composer/
After the switch, clear the cache and re-install the package:
composer clear-cache composer installCheck the network connectivity and switch to a stable environment. If the error persists, manually download the
.zipor.tar.gzpackage file and install it in a local directory.composer require alibabacloud/XXXXXX@dev --prefer-source
Example 2
Error message:

Cause:
When you install alibabacloud/cloudauth-20190307:3.9.2, its dependency alibabacloud/tea-oss-utils:0.3.1 requires guzzlehttp/psr7 version [1.0.0,...,2.0.0). However, the currently installed version of guzzlehttp/psr7 is fixed to [1.0.0,..,1.9.1]. This causes a dependency conflict.
Solution:
Force an update of the dependency version.
composer require alibabacloud/cloudauth-20190307 3.9.2 -WIn the
composer.jsonfile, add a version constraint for guzzlehttp/psr7 in the require section, for example, "guzzlehttp/psr7": "^1.0". Then, run the following command to update the dependency.composer updateDelete
composer.lockand run the following command to reinstall the dependencies.composer install --prefer-source
Question 12: What do I do if the "cURL error 60: SSL certificate problem: unable to get local issuer certificate" error message is returned when I call an API operation?
Causes:
The CA certificate package is not downloaded. The system lacks a trusted CA certificate file. As a result, cURL cannot verify the SSL certificate.
No CA certificate path is specified in the PHP cURL configurations. The
curl.cainfooropenssl.cafileparameter is not correctly configured in thephp.inifile.The PHP service is disabled: The PHP service is not enabled after the
php.inifile is modified. In this case, the configurations do not take effect.
Solutions:
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. Store the
cacert.pemfile in a fixed directory.ImportantMake sure that the file path does not contain Chinese characters or special characters. Otherwise, issues may arise.
Configure the path of the SSL certificate for PHP.
Open the PHP configuration file
php.ini. You can run thephp --inicommand to query the location of the file.In the
php.inifile, findcurl.cainfo, set its value to the absolute path of the CA certificate, and remove the leading ; from the configuration item.# Example curl.cainfo = "D:\path\to\cacert.pem" openssl.cafile = "D:\path\to\cacert.pem"Save the file after you make the modifications.
NoteReplace the
D:\path\to\cacert.pempath in the example with the absolute path of your CA certificate.
Restart the PHP service.
Question 13: What do I do if the "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" error message is returned when I fail to install Composer?
Causes:
Version conflicts:
Some dependencies are locked to a specific version by the
composer.lockfile.By default, Composer does not automatically update the dependency packages that are locked to a specific version.
For example,
alibabacloud/cloudauth-20190307requires version2.0.1ofalibabacloud/openplatform-20191219, which is locked to version1.0.3.
Incompatibility with the PHP version:
PHP 8.2 is used but some dependency packages support only PHP 5.4 to PHP 7.X.
For example,
ralouphie/mimey 2.1.0supports only PHP^5.4|^7.0, but your environment uses PHP8.2.27.
Solutions:
Forcibly upgrade the version of all dependency packages:
composer update --with-all-dependencies # Simplified command: composer update -WNoteThis command upgrades all dependency packages, including the dependency packages that are locked to a specific version by the composer.lock file. This resolves version conflicts.
Clear the
composer.lockandvendor/files and re-install the packages. This method is applicable to scenarios that contain severe dependency chaos.rm composer.lock vendor/ composer clear-cache composer installImportantThis operation removes all installed dependencies.
If a dependency package does not support PHP 8, temporarily downgrade to an earlier PHP version to maintain compatibility.
Question 14: What do I do if the "Script @php think service:discover handling the post-autoload-dump event returned with error code 255" error message is returned?
Causes:
After you run the composer install or update command, Composer attempts to run the
php think service:discovercommand of ThinkPHP to automatically discover services but failed. As a result, the entire installation process is interrupted.Out of memory (OOM) or other issues.
Solutions:
Temporarily disable the service discovery script and modify the
composer.jsonfile in the root directory.{ "scripts": { "post-autoload-dump": "@php think service:discover" } }Change to:
{ "scripts": { "post-autoload-dump": "@echo Skipping 'php think service:discover'" } }Run the
composer dump-autoloadcommand again.Add a PHP memory limit by adding the following configuration to the
php.inifile:memory_limit = 512M
Question 15: The "Undefined property: Darabonba\OpenApi\Models\Config::$tlsMinVersion" error occurs
Cause: The version of alibabacloud/darabonba-openapi is earlier than 0.2.14.
Solution: Run the following command to update the version of alibabacloud/darabonba-openapi to 0.2.14 or later.
composer require alibabacloud/darabonba-openapi >=0.2.14 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:
If you have questions or feedback, join the DingTalk group (ID: 60965016010) for technical support.