How to set http timeouts for Amazon AWS SDK for PHP - amazon-s3

I'm using the Amazon AWS SDK for PHP (namely, version 2.7.16) to upload files to an S3 bucket. How can I set a timeout for http/tcp operations (connection, upload, etc.)? Although I've googled a lot I wasn't able to find out how.
Sample code I'm using:
$awsS3Client = Aws\S3\S3Client::factory(array(
'key' => '...',
'secret' => '...'
));
$awsS3Client->putObject(array(
'Bucket' => '...',
'Key' => 'destin/ation.file',
'ACL' => 'private',
'Body' => 'content'
));
so I'd like to set a timeout on the putObject() call.
Thanks!

Eventually I helped myself:
$awsS3Client = Aws\S3\S3Client::factory(array(
'key' => '...',
'secret' => '...'
'curl.options' => array(
CURLOPT_CONNECTTIMEOUT => 5,
CURLOPT_TIMEOUT => 10,
)
));
Looks like AWS PHP uses curl internally, so network related options are set this way.

With SDK version 3 this can be configured using the http configuration key.
$awsS3Client = Aws\S3\S3Client([
'key' => '...',
'secret' => '...',
'http' => [
'connect_timeout' => 5,
'timeout' => 10,
]
]);

Related

Unable to run migrations on GCP with CakePHP 3.8

I am trying to set up my CakePHP 3.8 project on a GCP "Compute Engine" VM.
I have set up my app.php to use the following DB configuration:
'className' => 'Cake\Database\Connection',
'driver' => 'Cake\Database\Driver\Mysql',
'persistent' => false,
'datasource' => 'Database/Mysql',
'persistent' => false,
'host' => 'localhost',
'username' => 'user',
'password' => 'password',
'database' => 'dbname',
'prefix' => '',
'encoding' => 'utf8',
'timezone' => 'UTC',
'cacheMetadata' => true,
'log' => false,
'flags' => [
PDO::MYSQL_ATTR_INIT_COMMAND => "SET ##SESSION.sql_mode='';",
// uncomment below for use with Google Cloud SQL
PDO::MYSQL_ATTR_SSL_KEY => CONFIG.'ssl/client-key.pem',
PDO::MYSQL_ATTR_SSL_CERT => CONFIG.'ssl/client-cert.pem',
PDO::MYSQL_ATTR_SSL_CA => CONFIG.'ssl/server-ca.pem',
PDO::MYSQL_ATTR_SSL_VERIFY_SERVER_CERT => false
],
'cacheMetadata' => true,
'log' => false,
My problem happens when I try to run migrations. The site works just fine with the above configuration, however, if I run
$> php bin/cake.php migrations migrate
I get a slew of errors saying that it cannot connect, access denied for user#host.
If I add
'ssl_key' => CONFIG .'ssl/client-key.pem',
'ssl_cert' => CONFIG . 'ssl/client-cert.pem',
'ssl_ca' => CONFIG . 'ssl/server-ca.pem',
I get an error:
Caused by: [PDOException] PDO::__construct(): Peer certificate CN=`gcpname:gcpserver' did not match expected CN=`111.111.111.111' in /var/www/mydomain.com/vendor/robmorgan/phinx/src/Phinx/Db/Adapter/PdoAdapter.php on line 79
I guess this is because the migrations plugin still doesn't pass the flags or custom mysql_attr_* options over to the Phinx connection configuration, see this issue:
https://github.com/cakephp/migrations/issues/374
I don't think there's much that can be done here, other than adding support for flags / attribute options, or using Phinx directly (ie without the Migrations plugin).
I've pushed a PR that would add support for driver specific flags, you might want to give it a try and comment on the issue or the PR whether it works for you (it's for CakePHP 4.x (Migrations 3.x), I'll backport it for CakePHP 3.x (Migrations 2.x) in case it's being accepted):
https://github.com/cakephp/migrations/pull/478

How to change database

I am currently on a vps from ovh with prestashop 1.7.5. I ordered a CloudDB database.
I would like to know the handling to follow to be able to change the database because I do not find a solution to my problem.
thank you so much
PS: I'm a beginner with PrestaShop.
Using your FTP client or file manager open this file:
/app/config/parameters.php
Find the lines with database_host, database_name, database_user and
database_password parameters.
Replace existing values of that params with the new ones.
Save the file and upload it back to the server.
All done! Open your site in the browser and check whether it works.
<?php return array (
'parameters' =>
array (
'database_host' => '127.0.0.1',
'database_port' => '',
'database_name' => 'your_database_name',
'database_user' => 'your_database_user',
'database_password' => 'your_database_password',
'database_prefix' => 'ps_',
'database_engine' => 'InnoDB',
'mailer_transport' => 'smtp',
'mailer_host' => '127.0.0.1',
'mailer_user' => NULL,
'mailer_password' => NULL,
'secret' => 'Vz6rVXVYNWYt7E6Fvfvdfvg34MCdc97h3IttReewVIxNOu7wHAoS',
'ps_caching' => 'CacheMemcache',
'ps_cache_enable' => false,
'ps_creation_date' => '2017-05-22',
'locale' => 'en-US',
'cookie_key' => 'xduROM3yvjDSym43CvfdvFDVD47YG8zCrVruNFjjZ3NUb7Ut9',
'cookie_iv' => '7kBvdfvgh',
'new_cookie_key' => 'def00000766ffa61aae49b279evfsdvsdfvsfdvfdvwerr324r3frdfveb1afedc8702a964f0a1f6828bf1623ca54efad10ed4bbfb289beec62b01a3062d4c3ce78254157',
),
);

Laravel SQL Server connection with ENCRYPT=yes trustServerCertificate=true

I got a ubuntu docker container which runs php 5.5.9, laraverl 5.2 which can connect successfully to SQL Server and get results back.
The docker image I am using is https://hub.docker.com/r/h2labs/laravel-mssql/
The problem I got is that the server uses encryption and I cant find how to pass the following parameters to the laravel connection string for mssql
ENCRYPT=yes;trustServerCertificate=true
My SQL Server connection string at present looks like this
DB_CONNECTION=sqlsrv
DB_HOST=sql.mydomain.com
DB_PORT=1433
DB_DATABASE=mydbname
DB_USERNAME=mysusername
DB_PASSWORD=mypass
My laravel database config looks like this
'sqlsrv' => [
'driver' => 'sqlsrv',
'host' => env('DB_HOST', 'localhost'),
'database' => env('DB_DATABASE', 'forge'),
'username' => env('DB_USERNAME', 'forge'),
'password' => env('DB_PASSWORD', ''),
'charset' => 'utf8',
'prefix' => '',
],
The SQL Server error log entry is
Encryption is required to connect to this server but the client library does not support encryption; the connection has been closed. Please upgrade your client library. [CLIENT: 103.31.114.56]
Support for either option was not introduced until Laravel 5.4; Specifically, v5.4.11
So you would first need to upgrade to laravel/framework:>=5.4.11,<5.5
Then, to configure your application, you will need to modify your config/database.php file as follows:
// ...
'sqlsrv' => [
'driver' => 'sqlsrv',
'host' => env('DB_HOST', 'localhost'),
'database' => env('DB_DATABASE', 'forge'),
'username' => env('DB_USERNAME', 'forge'),
'password' => env('DB_PASSWORD', ''),
'charset' => 'utf8',
'prefix' => '',
'encrypt' => 'yes', // alternatively, defer to an env variable
'trust_server_certificate' => 'true', // alternatively, defer to an env variable
],
// ...
DatabaseServiceProvider, via ConnectionFactory and SqlServerConnector will use this to build the underlying PDO connection with those options set in the DSN.

NOAUTH Authentication required. Laravel + Redis

I am getting error NOAUTH Authentication required.
My laravel version is 5.3 and I am using predis 1.1.1 to connect redis.
in etc/redis/redis.conf I have:
bind 127.0.0.1
requirepass somepassword
in .env file I have
REDIS_HOST=127.0.0.1
REDIS_PASSWORD=somepassword
REDIS_PORT=6379
in config/database.php I have:
'redis' => [
'cluster' => false,
'default' => [
'host' => env('REDIS_HOST', '127.0.0.1'),
'password' => env('REDIS_PASSWORD', null),
'port' => env('REDIS_PORT', 6379),
'database' => 0,
],
I am connecting redis via:
self::$_db = \Redis::connection('default');
and using it like:
self::$_db->pipeline(function ($pipe) use ($profile, $time,$type, $id) {
$pipe->zadd(self::getProfileKey($profile, $type), $time, $id);
$pipe->zadd(self::getProfileKey($profile), $time, $type . ':' . $id);
$pipe->zadd(self::getModelKey($type,$id) . '::favoritedBy', $time, $profile->profile_id);
});
So, when I comment out requirepass and send password as null it works but it does not work and throw error NOAUTH Authentication required. when the password is in place. I need to have password in place as per my project requirement. Please help. Thanks in advance.
So after some research, I got a solution for this issue:
We need to add:
'options' => [
'parameters' => ['password' => env('REDIS_PASSWORD', null)],
],
In config array. See complete example below: database.php
'redis' => [
'cluster' => false,
'default' => [
'host' => env('REDIS_HOST', '127.0.0.1'),
'password' => env('REDIS_PASSWORD', null),
'port' => env('REDIS_PORT', 6379),
'database' => 3,
],
'options' => [
'parameters' => ['password' => env('REDIS_PASSWORD', null)],
],
],
In .env file:
REDIS_HOST=127.0.0.1
REDIS_PASSWORD=mmdgreat
REDIS_PORT=6379
I solve it downgrading the predis! :D
composer require predis/predis:0.8.4
I'm using the Laravel 5.3 too! :)

Is it still possible to use Itunes Connect API endpoints instead of Java Reporter tool?

Prior to the newest Itunes Connect update all requests were HTTP requests made through Curl in our application. After the update, Apple is recommending to use their new reporter tool.
https://github.com/mikebarlow/itc-reporter I want to do something similar to this if possible. This supposedly works without the reporter tool and it looks like it is still just making HTTP requests. I won't use this code in my project because it requires us to update PHP version which we have planned for another time.
Is it possible to make simple HTTP requests using Curl to get data? I don't want to use Guzzle if I don't have to!
$json = '{"userid":"{{USERNAME}}","password":"{{PASSWORD}}","version":"2.0","mode":"Robot.XML","account":"{{VENDOR_ID}}","queryInput":"[p=Reporter.properties, Sales.getReport, {{VENDOR_ID}},Sales,Summary,Weekly,20170108]"}'
CURLOPT_URL => 'https://reportingitc-reporter.apple.com/reportservice/sales/v1',
CURLOPT_HEADER => false,
CURLOPT_HTTPHEADER => array('Accept: text/xml, text/plain', 'Content-Type: text/xml, text/plain'),
CURLOPT_USERAGENT => 'Java/1.8.0_92',
CURLOPT_TIMEOUT => 10,
CURLOPT_SSL_VERIFYPEER => false,
CURLOPT_POST => true,
CURLOPT_POSTFIELDS => $json,
this is the request I've made while testing and when I run it I get the HTML response saying "Forbidden, You do not have access to this page"
I tried this while urlencoding username and password but I get the same result. I would love to be able to still get this data using Curl or we will have to work on adding the reporter tool into our application.
the postfield just needed to be changed accordingly
function build_json_request(, $access_token, $account_id,
$args_arr=array())
{
$args = $args_arr;
$json = array(
'accesstoken' => urlencode($access_token),
'version' => '2.2',
'mode' => 'Robot.XML',
'account' => $account_id
);
$queryInput = array(
'p=Reporter.properties',
array_shift($args)
);
if(! empty($args))
$queryInput[] = implode(',', $args);
$json['queryInput'] = '[' . implode(', ', $queryInput) . ']';
return json_encode($json);
}
$json = build_json_request('Sales.getReport', $access_token, $account_id, array('Sales.getReport', $vendor_id, 'Sales', 'Summary', 'Daily', $date) );
$output = process_curl(array(
CURLOPT_URL => 'https://reportingitc-reporter.apple.com/reportservice/sales/v1',
CURLOPT_HEADER => false,
CURLOPT_TIMEOUT => 10,
CURLOPT_SSL_VERIFYPEER => false,
CURLOPT_POST => true,
CURLOPT_POSTFIELDS => 'jsonRequest='.$json,
));