简体   繁体   中英

Amazon S3 on PHP GAE not working with curl extension

Could anyone help me figure out how to get S3 working on my php app engine ( runtime: php55 )?

I saw somewhere that you can use it without CURL and found the StreamWrapper but keep getting errors.

Use of undefined constant CURLE_COULDNT_RESOLVE_HOST
Use of undefined constant CURLE_COULDNT_CONNECT
Use of undefined constant CURLE_PARTIAL_FILE
etc..

Here is my code:

use Aws\S3\S3Client;
use Aws\S3\Exception\S3Exception;

// Instantiate an S3 client
$s3 = S3Client::factory(array('key' => 'KEY','secret' => 'SECRET'));
$s3->registerStreamWrapper(); // don't use curl

//AMAZON S3 BACKUP//
$document_data = "123456";
$s3_object_url = "s3://bucket/folder/file.txt";
$s3_options = stream_context_create(['s3'=>['ACL'=>'bucket-owner-full-control', 'ServerSideEncryption' => 'AES256']]);
$s3_file = fopen($s3_object_url, 'w', false, $s3_options);
fwrite($s3_file, $document_data);
fclose($s3_file);

Error when using curl lite:

PHP Fatal error:  Uncaught exception 'google\appengine\runtime\CurlLiteMethodNotSupportedException' with message 'curl_multi_init' in /base/data/home/runtimes/php/sdk/google/appengine/runtime/CurlLiteStub.php:1391
Stack trace:
#0 /base/data/home/apps/.../vendor/guzzle/guzzle/src/Guzzle/Http/Curl/CurlMulti.php(50): curl_multi_init()
#1 /base/data/home/apps/.../vendor/guzzle/guzzle/src/Guzzle/Http/Curl/CurlMultiProxy.php(128): Guzzle\Http\Curl\CurlMulti->__construct(1)
#2 /base/data/home/apps/.../vendor/guzzle/guzzle/src/Guzzle/Http/Curl/CurlMultiProxy.php(87): Guzzle\Http\Curl\CurlMultiProxy->getAvailableHandle()
#3 /base/data/home/apps/.../vendor/guzzle/guzzle/src/Guzzle/Http/Client.php(284): Guzzle\Http\Curl\CurlMultiProxy->send()
#4 /base/data/home/apps/.../vendor/aws/aws-sdk-php/src/Aws/Common/Client/AbstractClient.php(256): Guzzle\Http\Client->send(Ob in /base/data/home/runtimes/php/sdk/google/appengine/runtime/CurlLiteStub.php on line 1391

Error when using extension = "curl.so" in php.ini

15:09:52.614 A problem was encountered with the process that handled this request, causing it to exit. This is likely to cause a new process to be used for the next request to your application. (Error code 204)

EDIT:

It looks like "guzzle" needs curl enabled so I enabled extension = "curl.so" in my php.ini and it works fine in my localhost developer with no errors. But not when I upload it to app engine.

curl requires sockets which are only available to bill enabled apps ( https://cloud.google.com/appengine/docs/php/sockets/ ). You may wish to also consider "curl lite": https://cloud.google.com/appengine/docs/php/config/php_ini#GAE_directives

Even though GAE supports "cURL" - it is only a wrapper, so some functionality has not been implemented yet - particularly the whole multi_curl_* thing.

Have not found a way to deactivate it - but from SDK v3 cURL is not anymore required - so you might give that a try.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM