Connect silex 2 dbal connect app engine with cloud sql - symfony

I lost several hours trying to connect to cloud SQL from PHP flex env, but I found the answer.
I hope this help other people.
An exception occured in driver: SQLSTATE[HY000] [2002] No such file or directory
or
Access denied for user 'root'#'cloudsql' (using password: NO)

1.- enable Google Cloud SQL API: https://console.cloud.google.com/apis/
2.- get your cloud sql instance name
3.- add the beta_settings to your yaml
beta_settings:
cloud_sql_instances: "here-your-instance-name"
4.- config your doctrine dbal unix_socket
$app->register(new Silex\Provider\DoctrineServiceProvider(), array(
'dbs.options' => array (
'db_conn' => array(
'driver' => 'pdo_mysql',
'unix_socket' => '/cloudsql/here-your-instance-name',
'host' => 'localhost',
'dbname' => 'your-database',
'user' => 'your-user',
'password' => 'your-password',
'charset' => 'utf8',
'collate' => 'utf8_spanish2_ci'
)
)
));

Related

Why is Oneup/UploaderBundle so slow to upload a 'big' file (1GB)?

In a Symfony project, I have implemented the Oneup/UploaderBundle with the Oneup/FlysystemBundle to upload files to a S3 compatible storage.
I tried to upload a 1GB file, and it took about 3 min using the Aws\S3\S3Client adapter (https://flysystem.thephpleague.com/docs/adapter/aws-s3-v3/), which is way too slow.
oneup_uploader.yaml :
object_scaleway_sync:
frontend: dropzone
storage:
type: flysystem
filesystem: oneup_flysystem.object_scaleway_sync_filesystem
oneup_flysystem.yaml :
oneup_flysystem:
adapters:
xxx_fr_sync.flysystem_adapter:
awss3v3:
client: xxx_fr.sync_s3_client
bucket: 'xxxtest'
prefix: ''
filesystems:
object_scaleway_sync:
adapter: xxx_fr_sync.flysystem_adapter
After that, I tried to upload the same file using directly the S3Client in a controller, and it took about 98 seconds, which is faster, but still too slow for 1GB.
MainController.php :
$client = new S3S3Client([
'region' => 'fr-par',
'endpoint' => 'https://s3.fr-par.scw.cloud',
'version' => 'latest',
'credentials' => [
'key' => 'publickey',
'secret' => 'secretkey'
]
]);
$pathToFile = $this->getParameter('kernel.project_dir') . '/public/big.bin';
$resource = \fopen($pathToFile, 'r');
$result = $client->putObject([
'Bucket' => 'xxxtest',
'Key' => 'big.bin',
'Body' => $resource
]);
return new Response("Ok");
Strangely, this simple plain php script below took 28 seconds to upload the same file :
$s3 = new Aws\S3\S3Client([
'region' => 'fr-par',
'version' => 'latest',
'endpoint' => 'https://s3.fr-par.scw.cloud',
'credentials' => [
'key' => "publickey",
'secret' => "secretkey",
]
]);
$result = $s3->putObject([
'Bucket' => 'xxxtest',
'Key' => 'big.bin',
'SourceFile' => './big.bin'
]);
Why is this script faster than the Symfony method ? Is there a way to optimize the upload speed ?
I tried using the async S3 Simple Client (https://async-aws.com/integration/simple-s3.html) but it returned the error "Could not contact remote server" at the end of the upload.
Same error with the async S3Client (https://async-aws.com/clients/s3.html).

After Move http to https of wordpress thrid party API's not working

I have implemented the sigle signon in worpress with Java with Aws cognito.
it is working fine with http but after moving http to https. API's are not working and throwing the error below:
WP_Error Object
(
[errors] => Array
(
[http_request_failed] => Array
(
[0] => cURL error 35: error:1408F10B:SSL routines:ssl3_get_record:wrong version number
)
)
[error_data] => Array
(
)
)
I have consumed the get and Post API like below:
$bodyData = array(
'username' => $_POST['username'],
'password' => $_POST['password']
);
$response = wp_remote_post('https://example.com:8083/digitalIdentityProvider/login',
array(
'method' => 'POST',
'timeout' => 45,
'redirection' => 5,
'httpversion' => '2.0',
'sslverify' => true,
'blocking' => true,
'headers' => array('Content-Type'=> 'application/json'),
'body' => json_encode($bodyData) ,
'cookies' => array()
));
Could you please someone guide or suggest ?
Thanks.
After playing with wordpress code and AWS, I found the issue with Aws ELB and Load Balancer .
SSL Certificate has applied to LB and Third party API and wordpress were hosted on AWS EC2 and for EC2 there was not SSL certificate and I was trying to access API with
HTTPS:
https://example.com:8083/digitalIdentityProvider/login hence request was not verifying over there hence I was not receiving any response from API.
I have changed API call
from https://example.com:8083/digitalIdentityProvider/login
to http://example.com:8083/digitalIdentityProvider/login
after change it https to http. it working fine.

Read Replica configuration in drupal

I have hosted my drupal site on amazon and wanted to scale the dbserver to handle the increased traffic. I have enabled Read Replica of dbinstance of RDS. I dont know what all changes have to be done from drupal end to get this working.
If anyone has configured the above implementation into their site then some pointers would be really appreciated.
Since Drupal 7, they made it very easy to use it with MySQL master(Read/Write)-slave(Read-only) setup. Assume that we have 2 MySQL servers configured in master-slave mode.
In settings.php, start with the MySQL master configuration.
$databases['default']['default'] = array(
'driver' => 'mysql',
'database' => 'mysql-master-db',
'username' => 'mysql-master-username',
'password' => 'mysql-master-password',
'host' => 'mysql-master(Read + Write)-IP',
);
Now below this, add the following code to configure the slaves.
$databases['default']['slave'][] = array(
'driver' => 'mysql',
'database' => 'mysql-slave1-db',
'username' => 'mysql-slave1-user',
'password' => 'mysql-slave1-password',
'host' => 'mysql-slave1(Read-only)-IP',
);
Now below this, if you want any of the select queries to use the slave server, then use the following syntax:
$query = db_select('node', 'n', array('target' => 'slave'));
By providing array('target' => 'slave') argument, the query will run against one of the slave databases. If there are multiple such queries for the same page, then all will run on the same slave server. If no slave is available, then that option will be ignored and the query will run against the master.

Edit mail.inc to enable SMTP server for sending mail

i want to place the following codes into include/mail.inc of Drupal7 so that i can send mail from SourceForge's project web space. Don't ask me to install SMTP Authentication Support, and i don't have access to php.ini , I wonder where should these codes be placed? Thanks in advance!
include('Mail.php');
$recipients = array( 'someone#example.com' ); # Can be one or more emails
$headers = array (
'From' => 'someone#example.com',
'To' => join(', ', $recipients),
'Subject' => 'Testing email from project web',
);
$body = "This was sent via php from project web!\n";
$mail_object =& Mail::factory('smtp',
array(
'host' => 'prwebmail',
'auth' => true,
'username' => 'YOUR_PROJECT_NAME',
'password' => 'PASSWORD', # As set on your project's config page
#'debug' => true, # uncomment to enable debugging
));
$mail_object->send($recipients, $headers, $body);
if this code could success send email without drupal7 (you must make sure it)
then you could do it in three ways:
write a drupal 7 module ,copy mail.php into *.module, and make the rest code as a function,that's the way as the handbook of drupal.
just copy all of the code to you theme/page.tpl.php , and run it directly , a little dirty
hack drupal core , include/mail.inc , just change function drupal_mail_send

Migrate Drupal site from XAMPP to MAMP

I created a Drupal website in a XAMPP environment, but would like to further develop it in a MAMP environment. That is, without losing all the content I already added. I changed the settings.php file like this
$databases = array (
'default' =>
array (
'default' =>
array (
'database' => 'drupal',
'username' => 'root',
'password' => 'root',
'host' => 'localhost:8889',
'port' => '',
'driver' => 'mysql',
'prefix' => '',
),
),
);
But I get the error:
PDOException: SQLSTATE[HY000] [2005] Unknown MySQL server host 'localhost:8889' (2) in lock_may_be_available() (line 164 of /Applications/MAMP/htdocs/kooknet2/includes/lock.inc).
Does anyone know how I can solve this? Thanks!
It's a tiny error, you've got the port as part of your host string (:8889) when you should be adding it to the array key that actually says port. Try this:
$databases = array (
'default' => array (
'database' => 'drupal',
'username' => 'root',
'password' => 'root',
'host' => 'localhost',
'port' => '8889',
'driver' => 'mysql',
'prefix' => '',
),
),
);
If you have local MySQL server, login to it from console, check user-pass-port. It see,s you haven't MySQL instance on 8899 port
I would suggest using the backup and migrate module to grab a copy of your database. Then setup your site on mamp (with a new db/install), and use BAM to restore from your backup.
If you're using the same file path, there shouldn't be any other steps to worry about otherwise you might need to copy/move your files directory and also reconfigure your file path settings in the drupal interface. (Also you may need to be aware that any links to internal content that is embedded in your node body may also need to be adjusted so the path is correct)

Resources