aws s3 php: fails to upload directory using UploadSyncBuilder - php

I am trying to upload a 14MB directory to s3 using aws php sdk. These are following scenarios and their results
Upload from my local system(india) to s3(us-east-1): success
Upload from ec2(ap-southeast-1) to s3(ap-southeast-1): success
Upload from ec2(ap-southeast-1) to s3(us-east-1): FAIL
The following code I have used
require('application/classes/vendor/autoload.php');
use Aws\S3\S3Client;
use Aws\Common\Credentials\Credentials;
use Aws\S3\Sync\UploadSyncBuilder;
use Guzzle\Log\ClosureLogAdapter;
use Guzzle\Plugin\Log\LogPlugin;
$newCredentials = new Credentials("API_KEY", "SECRET_KEY");
$s3 = S3Client::factory();
//$logPlugin = Guzzle\Plugin\Log\LogPlugin::getDebugPlugin();
$stream = fopen('out.log', 'w');
$logPlugin = new LogPlugin(new ClosureLogAdapter(function ($m) use ($stream) {
fwrite($stream, $m . PHP_EOL);
}), "# Request:\n{request}\n\n# Response:\n{response}\n\n# Errors: {curl_code} {curl_error}", true);
$s3->addSubscriber($logPlugin);
$s3->setCredentials($newCredentials);
$s3->setRegion("us-east-1");
UploadSyncBuilder::getInstance()
->setClient($s3)
->setBucket("BUCKET")
->setAcl("public-read")
->uploadFromDirectory("/mnt/1410503562Welcome to Leap!.zip_ext")
->setKeyPrefix("customs3/game10906/1410501964WelcometoLeap.zip_ext")
->setConcurrency(5)
->build()
->transfer();
Exception
PHP Fatal error: Uncaught exception 'Guzzle\Service\Exception\CommandTransferException' with message 'Errors during multi transfer (Guzzle\Http\Exception\RequestException) ./application/classes/vendor/guzzle/guzzle/src/Guzzle/Http/Message/Request.php line 569
Error completing request
#0 ./application/classes/vendor/guzzle/guzzle/src/Guzzle/Http/Message/Request.php(378): Guzzle\Http\Message\Request->processResponse(Array)
#1 ./application/classes/vendor/guzzle/guzzle/src/Guzzle/Http/Message/EntityEnclosingRequest.php(49): Guzzle\Http\Message\Request->setState('complete', Array)
#2 ./application/classes/vendor/guzzle/guzzle/src/Guzzle/Http/Curl/CurlMulti.php(286): Guzzle\Http\Message\EntityEnclosingRequest->setState('complete', Array)
#3 ./application/classes/vendor/guzzle/guzzle/src/Guzzle/Http/Curl/CurlMulti.php(244): Guzzle\Http\Curl\CurlMulti->processResponse(Object(Guzzle\Http\Message\EntityEnclosingRequest), Object(Guzzle\Http\Curl\CurlHandle), Array)
#4 ./application/classes/vendor/guzzle/guzzle in /vol/selfserve/application/classes/vendor/guzzle/guzzle/src/Guzzle/Service/Exception/CommandTransferException.php on line 25
I have setup log to debug and dig through Guzzle library as well. I found that when it fails, for a request no response comes. When I set concurrency to 1, it succeeds but takes much time. It fails even at concurrency of 2.
If any file fails, whole upload fails leaving it in partial uploaded state. I could not find any way to set options to retry if something fails.
Thanks for help!

After contacting with AWS support I was able to solve this with their help. Issue was in guzzle library. Following is the response from AWS support
This error occurs when cURL fails to rewind a stream and does not
associate an error with a curl handle. We've added checks to account
for this situation and automatically retry. Please ensure that they
are using the latest version of the SDK and version 3.9.2+ of Guzzle.

Related

Adding User to Chef via Chef Server API

I am attempting to create a user on my Chef Server through the Chef Server API. I am currently using a PHP wrapper for the API interface which can be found here.
I understand that in order to create a user using the API, you must provide the pivotal.pem file as well as the pivotal username.
Here is a snippet of my PHP code that I am using:
// ENVIRONMENT VARIABLES
// The URL for the Chef Server
$server = "mycompany.com";
// The name used when authenticating
$client = 'pivotal';
// The location of the file which contains the client key
$key = "../../../pivotal.pem";
// The version of the Chef Server API that is being used
$version = "12.0.2";
// Create a Chef object
$chef = new Chef($server, $client, $key, $version);
// API Request
$createUserRequest = array("name"=>$displayName, "display_name"=>$displayName, "email"=>$emailAddress, "password"=>$password);
$createUserRequest = json_encode($createUserRequest);
$chef->post('/users/', $createUserRequest);
Here is the reponse that I receive from the server:
Fatal error: Uncaught exception 'Exception' with message 'Invalid signature for user or client 'pivotal'' in C:\Workspace\SA_SSAF\app\plugin\CHEF\Chef PHP\src\Jenssegers\Chef\Chef.php:187
Stack trace:
#0 C:\..\..\app\plugin\CHEF\Chef PHP\src\Jenssegers\Chef\Chef.php(70): Jenssegers\Chef\Chef->api('/users/', 'POST', '{"name":"entra"...')
#1 C:\..\..\app\plugin\CHEF\controller\chefEnrollUser.php(55): Jenssegers\Chef\Chef->post('/users/', '{"name":"entra"...')
#2 {main}
thrown in C:\..\..\app\plugin\CHEF\Chef PHP\src\Jenssegers\Chef\Chef.php on line 187
If I try and perform a GET request using the same configuration, I receive a successful response.
Any clues as to why something like this may be happening?
Thanks

Gitkit_ServerException: Error code: 17

I'm attempting to implement the password reset flow for Google Identity Toolkit with the php sdk. I am able to use the sdk to do everything needed except setting up the mail endpoint which exits with the following error.
Here is the code that generates the exception:
try {
$oobResult = $gitkitClient->getOobResults();
echo $oobResult['response_body'];
}
catch (Exception $e) {
print "Exception $e";
}
And the exception:
Exception exception 'Gitkit_ServerException' with message 'Error code: 17' in C:\...\vendor\google\identity-toolkit-php-client\src\RpcHelper.php:229
Stack trace:
#0 C:\...\vendor\google\identity-toolkit-php-client\src\RpcHelper.php(208): Gitkit_RpcHelper->checkGitkitError(Array)
#1 C:\...\vendor\google\identity-toolkit-php-client\src\RpcHelper.php(179): Gitkit_RpcHelper->invokeGitkitApiWithServiceAccount('getOobConfirmat...', Array)
#2 C:\...\vendor\google\identity-toolkit-php-client\src\GitkitClient.php(371): Gitkit_RpcHelper->getOobCode(Array)
#3 C:\...\vendor\google\identity-toolkit-php-client\src\GitkitClient.php(299): Gitkit_Client->buildOobLink(Array, 'resetPassword')
#4 C:\...\auth\mail.php(14): Gitkit_Client->getOobResults(Array, '192.168.1.1')
Does anyone know what this error indicates and how to resolve it?
This function from the readme.md generates the same 'Error code: 17'
$gitkitClient->getEmailVerificationLink("emailgoeshere");
These functions from the readme.md do work as expected:
$gitkitClient->getUserById("useridgoeshere");
$gitkitClient->deleteUser("useridgoeshere");
$gitkitClient->getAllUsers(3);
This is caused by a known issue on Identity Toolkit and is now fixed. Can you go the Google Developer Console and make sure you have the correct send email endpoint in your Identity Toolkit config? Also make sure you put the same send email endpoint in your widget config. It should work now.

Need help updating a google spreadsheet cell using Zend gdata with PHP. I keep getting an error with the updateCell function

I have been trying to update a cell in a google spreadsheet. I'm using ZendFramework-1.12.6 and PHP Version 5.5.9. The response I get using the code is:
ERROR: Expected response code 200, got 400 The spreadsheet at this URL could not be found. Make sure that you have the right URL and that the owner of the spreadsheet hasn't deleted it.
And if I remove the error trapping I get this message:
Fatal error: Uncaught exception 'Zend_Gdata_App_HttpException' with message 'Expected response code 200, got 400 Missing resource version ID' in /volume1/web/Zend/Gdata/App.php:717 Stack trace: #0 /volume1/web/Zend/Gdata/App.php(933): Zend_Gdata_App->performHttpRequest('PUT', '', Array, 'put(Object(Zend_Gdata_Spreadsheets_CellEntry), NULL, NULL, NULL, Array) #2 /volume1/web/Zend/Gdata/App/Entry.php(209): Zend_Gdata_App->updateEntry(Object(Zend_Gdata_Spreadsheets_CellEntry), NULL, NULL, Array) #3 /volume1/web/Zend/Gdata/Spreadsheets.php(307): Zend_Gdata_App_Entry->save() #4 /volume1/web/gss.php(19): Zend_Gdata_Spreadsheets->updateCell('1', '1', 'test', '1zoCs23pKzQXPtB...', 'od6') #5 {main} thrown in /volume1/web/Zend/Gdata/App.php on line 717
It seems like everything works great until I try writing the string 'test' to the spreadsheet with the updateCell call. Can anyone help?
<?php
// load Zend Gdata libraries
require_once 'Zend/Loader.php';
Zend_Loader::loadClass('Zend_Gdata_Spreadsheets');
Zend_Loader::loadClass('Zend_Gdata_ClientLogin');
// set credentials for ClientLogin authentication
$user = "mygmailaccount#gmail.com";
$pass = "mypassword";
// connect to API
$service = Zend_Gdata_Spreadsheets::AUTH_SERVICE_NAME;
$client = Zend_Gdata_ClientLogin::getHttpClient($user, $pass, $service);
$service = new Zend_Gdata_Spreadsheets($client);
// set target spreadsheet and worksheet
$ssKey = '1zoCs23pKaQXPtB2rT5Rn6KVzJalIoR5VYBnlURJRRLs';
$wsKey = 'od6';
$service->updateCell('1', '1', 'test', $ssKey, $wsKey);
?>
After several hours of troubleshooting this same problem, I eventually figured out that this is a bug or a missing feature with the "new" Google Spreadsheets.
See the comments on this post: Updating cell in Google Spreadsheets returns error "Missing resource version ID" / "The remote server returned an error: (400) Bad Request."
Information on the "new" Google Sheets: https://support.google.com/drive/answer/3541068
On that page is a link that allows you to create a new spreadsheet using the "old" Sheets: https://g.co/oldsheets
My solution was to create a new "old" sheet. I'm now able to use updateCell with no problems!
I just found your question and with some additional information I found a really easy solution so I thought I'd share that too.
The problem seems to be, that there needs to be an Etag set for the skript to perform correctly. This Etag is
array('If-Match'=> '*')
To add this as a header to every UpdateCell request go into the source file in the library path:
library/Zend/Gdata/Spreadsheets.php
and change the UpdateCell method definition from
$entry = $this->getCellEntry($query);
$entry->setCell(new Zend_Gdata_Spreadsheets_Extension_Cell(null, $row, $col, $inputValue));
$response = $entry->save();
to
$entry = $this->getCellEntry($query);
$entry->setCell(new Zend_Gdata_Spreadsheets_Extension_Cell(null, $row, $col, $inputValue));
$response = $entry->save(null,null,array('If-Match'=> '*'));
Requests are now working for me as previously.

Unable to run OpenTok's WebRTC demo

Recently I tried to use OpenTok's WebRTC demo for a web application requiring peer-to-peer video/audio communication.
I went through the tutorials on http://www.tokbox.com/opentok/webrtc/docs/js/tutorials/ and http://www.tokbox.com/opentok/docs/server/server_side_libraries.html and I got something working using JavaScript (client-side) and PHP's library (server-side) for token/session generation.
I managed to code a basic peer-to-peer chat room locally. However, as soon as I upload it to a web server it blows up returning the following error:
Fatal error: Uncaught exception 'RequestException' with message 'Request error: Failed
to connect to 70.42.47.98: Permission denied' in /home/www/dummy_url.com/php-
sdk/SDK/Opentok-PHP-SDK/OpenTokSDK.php:192 Stack trace: #0 /home/www/dummy_url.com/php-
sdk/SDK/Opentok-PHP-SDK/OpenTokSDK.php(107): OpenTokSDK->_do_request('/session/create',
Array) #1 /home/www/dummy_url.com/php-sdk/SDK/Opentok-PHP-SDK/OpenTokSDK.php(221):
OpenTokSDK->createSession('74.96.245.119', Array) #2 /home/www/dummy_url.com/php-
sdk/index.php(16): OpenTokSDK->create_session('74.96.245.119', Array) #3 {main} thrown
in /home/www/dummy_url.com/php-sdk/SDK/Opentok-PHP-SDK/OpenTokSDK.php on line 192
I took a look at line 192:
//die(function_exists('curl_version')); // debugging
$res = curl_exec($ch);
if(curl_errno($ch)) {
throw new RequestException('Request error: ' . curl_error($ch)); // <=== LINE 192
}
curl_close($ch);
and verified the server had curl enabled. It does.
Then I tried to run the demo test and it fails at:
Assertion Failed: File '/home/www/skillfullearning.net/test/test/TestOpenTokSDK.php'
Line '102'
Code ''
What's in Line '102'? This:
...
$token = $a->generateToken("mysession", RoleConstants::MODERATOR, gmmktime() + 100000);
assert('$token');
$token = $a->generateToken("mysession", RoleConstants::MODERATOR, gmmktime());
assert('$token');
try {
$token = $a->generateToken("mysession", RoleConstants::MODERATOR, gmmktime() +
1000000);
assert(false);
} catch (Exception $e) {
assert('$e'); // <================ LINE 102
}
...
I really don't know where to go from here. I would really appreciate some help with this matter.
/E
The error is caused by outdated tests. Here is an outstanding issue, hopefully it will be resolved soon. if you simply remove the test files, you would not have that problem anymore.

Amazon soap interface using php

Hi i am trying to use soap to get results from amazon, and i havent tried this before so i was trying some sample code. The problem is i get an error.
the code is this:
<?php
#Use the NuSOAP php library
//require_once('lib/nusoap.php');
$params->AWSAccessKeyId = AMAZON_API_KEY;
$params->Request->SearchIndex = 'Books';
$params->Request->Keywords = 'php5';
$amazon = new SoapClient('http://webservices.amazon.com/AWSECommerceService /AWSECommerceService.wsdl');
$result = $amazon->itemSearch($params);
echo $result;
?>
and this is the error i get when i run it. thanx for your time
Fatal error: Uncaught SoapFault exception: [aws:Client.MissingParameter] The request must contain the parameter Signature. in C:\wamp\www\amasearch.php:11 Stack trace: #0 [internal function]: SoapClient->__call('itemSearch', Array) #1 C:\wamp\www\amasearch.php(11): SoapClient->itemSearch(Object(stdClass)) #2 {main} thrown in C:\wamp\www\amasearch.php on line 11
Weird. The WSDL doesn't have a signature parameter for any type. BUT, I found this in Amazon dev forums. Recommend you to check it out (also, if you develop using amazon services, keep that resource at hand
https://forums.aws.amazon.com/ann.jspa?annID=483
Looks like security gates for services are now taller and bigger, mate
EDIT: This question link to some example in C#. Maybe it can help you out Amazon (AWS) - The request must contain the parameter Signature
And this is an example in AWS forums with PHP https://forums.aws.amazon.com/message.jspa?messageID=149715

Categories