Resolve the CURLOPT_CLOSEPOLICY undefined constant warning in the OSS PHP SDK, caused either by PHP 5.6.0 removing the constant or by a missing curl installation.
Problem description
When using the OSS PHP SDK, the following error appears:
Use of undefined constant CURLOPT_CLOSEPOLICY - assumed
'CURLOPT_CLOSEPOLICY' in
D:\phptools\www\pia\oss_php_sdk_20140625\lib\requestcore\requestcore.class.php on line 610:
This error has two distinct causes. Run the following commands to identify which one applies to your environment before proceeding:
# Check your PHP version
php -v
# Check whether curl is loaded
php -m | grep curl
If your PHP version is 5.6.0 or later and curl appears in the output, see Cause 1: PHP 5.6.0 removed CURLOPT_CLOSEPOLICY.
If curl does not appear in the output, see Cause 2: curl is not installed or not configured.
Cause 1: PHP 5.6.0 removed CURLOPT_CLOSEPOLICY
PHP 5.6.0 removed the CURLOPT_CLOSEPOLICY constant. The OSS PHP SDK still references this constant in requestcore.class.php, triggering the warning at runtime.
Fix
Because the official SDK has not been updated, remove the CURLOPT_CLOSEPOLICY reference from the SDK source file:
Open the following file in your SDK installation:
lib/requestcore/requestcore.class.php
Search for
CURLOPT_CLOSEPOLICYand delete or comment out the line where this constant is used.-
Save the file and re-run your code to confirm the warning is gone.
NoteThis is a workaround for a known compatibility gap in the SDK. Once the SDK is officially updated to remove this reference, revert this manual edit.
Cause 2: curl is not installed or not configured
The OSS PHP SDK requires the curl extension. If curl is missing or its path is not configured correctly, PHP cannot call curl functions, which triggers this error.
Fix
Install the curl extension or specify the curl environment variable, then restart your web server.
After installation, verify that the curl extension is loaded:
php -m | grep curl
If curl appears in the output, the extension is active.
Applicable scope
Object Storage Service (OSS)