I created a PHP script to retrieve some datas from my Google Cloud Platform account. Below is how I did :
<?php
require __DIR__ . '/vendor/autoload.php';
use Google\Cloud\BigQuery\BigQueryClient;
putenv('GOOGLE_APPLICATION_CREDENTIALS=key.json');
$projectId = 'xxxxx';
$datasetId = 'xxxxxx';
$table = 'xxxxx';
$bigQuery = new BigQueryClient([
'projectId' => $projectId
]);
// etc...
Everything works fine on my local computer (WAMP) but when I migrate my script to my company production environment, there is a problem :
Fatal error: Uncaught exception
'Google\Cloud\Core\Exception\ServiceException' with message 'cURL
error 6: Couldn't resolve host 'www.googleapis.com'
In fact I was excepting this message because every time I use Curl, I need to set our company proxy info :
<?php
curl_setopt($curl, CURLOPT_HTTPPROXYTUNNEL, true);
curl_setopt($curl, CURLOPT_PROXY, 'xxx.xxx.xxx.xxx');
By the way, i'm 100% sure that googleapis.com is white-listed by our proxies... but how to do it with the BigQueryClient ? I searched in the official documentation, no way to find how to use a proxy.
I would try passing blindly these constructions to one of the connection builder classes, hopefully one picks this up
'restOptions' => [
'proxy', 'xxx.xxx.xxx.xxx'
]
on the other hand if you have a trace log you could see if Guzzle or something else is used. Consider opening an issue tracking at: https://github.com/GoogleCloudPlatform/google-cloud-php/issues
Bigquery uses www.googleapis.com as its endpoint.
The command line instructions have global flags to specify an address, password, port and user name regarding a proxy usage, however, for client libraries you'll need to verify the access with your infrastructure team.
Use php's putenv() to set the proxy before using BigQueryClient.
putenv('HTTPS_PROXY=192.168.1.1:8080');
use Google\Cloud\BigQuery\BigQueryClient;
use GuzzleHttp\Client;
use Psr\Http\Message\RequestInterface;
$guzzleClient = new Client();
$config = [
'projectId' => 'xxx',
'keyFilePath' => 'key_path',
'restOptions' => [
'proxy' => 'xxx.xxx.xxx.xxx:xx'
],
'authHttpHandler' => function (RequestInterface $request, array $options = []) use ($guzzleClient) {
return $guzzleClient->send(
$request,
$options + [
'proxy' => 'xxx.xxx.xxx.xxx:xx'
]
);
}
];
$bigQueryClient = new BigQueryClient($config);
It works for me with php library google/cloud-bigquery version 1.8.0
Related
I am using the AWS facade for Laravel and I can instantiate a CloudSearchDomainClient object like this:
$c = AWS::createClient('cloudsearchdomain', ['endpoint' => '{our-endpoint}']);
But when I attempt to search like so:
$c->search(['query' => 'test']);
I get this error: Aws\CloudSearchDomain\Exception\CloudSearchDomainException with message 'Error executing "Search" on "2013-01-01/search"; AWS HTTP error: cURL error 6: Could not resolve host: 2013-01-01
It thinks the version is the endpoint.
I have the proper .env vars, eg. AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY and AWS_DEFAULT_REGION. I am able to use other AWS services, but CloudSearch specifically is a problem. What am I doing incorrectly?
I think you are mixing two things. An endpoint is a domain and api version is a date. So it should be more like this:
$c = AWS::createClient(
'cloudsearchdomain',
[
'endpoint' => 'https://example.com',
'apiVersion' => '2013-01-01',
]
);
I'm trying to authenticate the SpeechClient using 'keyFilePath' and 'projectId' parameters like so:
$speech = new SpeechClient([
'projectId' => 'actualProjectId,
'keyFilePath' => $key_path,
]);
If I use Google\Cloud\Speech\SpeechClient - Everything works fine, but if I use Google\Cloud\Speech\V1\SpeechClient I end up with an error: Could not construct ApplicationDefaultCredentials
I've read Google docs for Setting Up Authentication but still don't understand what am I doing wrong.
I need the V1 (in fact V1p1beta1) for additional features that are not available using the old SpeechClient.
Any ideas?
P.S. Using Laravel as the back-end.
For clients within the V1, etc. namespaces, pass the keyFilePath as credentials.
new SpeechClient([
'credentials' => $key_path
]);
I am setting up the google cloud client library from the below url:
https://cloud.google.com/bigquery/docs/reference/libraries#client-libraries-usage-php
I have created a key from the given url:
https://console.cloud.google.com/apis/credentials/
and set it up in the environment variable.
but i am getting the below error:
Please help.
it work on command prompt something like:
php yourphpfilename.php
also you have an alternate way to pass the key file:
$credentialsFile = '[PATH_TO_JSON_KEY_FILE]';
# Instantiates a client
$bigquery = new BigQueryClient([
'projectId' => $projectId,
'keyFilePath' => $credentialsFile
]);
Hope it will help you.
I have created php file. It contains details about to access (wsdl)xml file and function. I need to call a function with paramaters but i can't able to call a function. So, I have been given a WSDL file and I need to create a SOAP service for it in PHP. Could any one tell me what the correct way of doing it is?
Here is link of the WSDL: http://178.211.55.56/se/ws/wf_ws.php?wsdl
and
Here is my php code:
require_once 'lib/nusoap.php';
ini_set("soap.wsdl_cache_enabled", "0");
$soapclient = new nusoap_client("http://178.211.55.56/se/ws/wf_ws.php?wsdl",'wsdl');
$soapclient->setHTTPProxy("soap:address_location",8080,"usr_name","pwd");
when run above the php code return this error:
wsdl error: Getting "WSDL link" - HTTP ERROR: Couldn't open socket
connection to server "WSDL link" prior to connect(). This is often a
problem looking up the host name.
Try to use http://php.net/manual/en/class.soapclient.php
All you need is:
Create SOAP client:
$client = new SoapClient("http://178.211.55.56/se/ws/wf_ws.php?wsdl");
You can pass many options to the constructor, such as proxy, cache settings, etc.
Some examples for you:
$client = new SoapClient("some.wsdl", array('soap_version' => SOAP_1_2));
$client = new SoapClient("some.wsdl", ['login' => "some_name", 'password'=> "some_password"]);
$client = new SoapClient("some.wsdl", ['proxy_host' => "localhost", 'proxy_port' => 8080]);
If ssl certificate is wrong you can ignore it. Example is here: https://gist.github.com/akalongman/56484900eaf19b18cfbd
Call one of the service defined functions:
$result = $client->getResult(['param_name' => 'param_value']);
Pay attention that your service function may have required parameters. Usually it can be found in the result message.
I installed AWS PHP SDK and am trying to use SES. My problem is that it's (apparently) trying to read ~/.aws/credentials no matter what I do. I currently have this code:
$S3_AK = getenv('S3_AK');
$S3_PK = getenv('S3_PK');
$profile = 'default';
$path = '/home/franco/public/site/default.ini';
$provider = CredentialProvider::ini($profile, $path);
$provider = CredentialProvider::memoize($provider);
$client = SesClient::factory(array(
'profile' => 'default',
'region' => 'us-east-1',
'version' => "2010-12-01",
'credentials' => [
'key' => $S3_AK,
'secret' => $S3_PK,
]
));
And am still getting "Cannot read credentials from ~/.aws/credentials" error (after quite a while).
I tried 'credentials' => $provider of course, that was the idea, but as it wasn't working I reverted to hardcoded credentials. I've dumped $S3_AK and $S3_PK and they're fine, I'm actually using them correctly for S3, but there I have Zend's wrapper. I've tried ~/.aws/credentials (no ".ini") to the same result. Both files having 777 permissions.
Curious information: I had to set memory limit to -1 so it would be able to var_dump the exception. The html to the exception is around 200mb.
I'd prefer to use the environment variables, all though the credentials file is fine. I just don't understand why it appears to be trying to read the file even though I've hardcoded the credentials.
EDIT: So a friend showed me this, I removed the profile and also modified the try/catch and noticed the client seems to be created properly, and the error comes from trying to actually send an email.
The trick is just remove 'profile' => 'default' from the factory params, if this is defined we can't use a custom credentials file or environment variables. Is not documented but just works.
I'm using Sns and Sdk v3.
<?php
use Aws\Credentials\CredentialProvider;
$profile = 'sns-reminders';
$path = '../private/credentials';
$provider = CredentialProvider::ini($profile, $path);
$provider = CredentialProvider::memoize($provider);
$sdk = new Aws\Sdk(['credentials' => $provider]);
$sns = $sdk->createSns([
// 'profile' => $profile,
'region' => 'us-east-1',
'version' => 'latest',
]);
This solution will probably only work if you're using version 3 of the SDK. I use something similar to this:
$provider = CredentialsProvider::memoize(CredentialsProvider::ini($profile, $path));
$client = new SesClient([
'version' => 'latest',
'region' => 'us-east-1',
'credentials' => $provider]);
I use this for S3Client, DynamoDbClient, and a few other clients, so I am assuming that the SesClient constructor supports the same arguments.
OK, I managed to fix it.
I couldn't read the credentials file but it wasn't exactly my idea.
What was happening was that the actual client was being created successfully, but the try/catch also had the sendEmail included. This was what was failing.
About creating the client with explicit credentials: If you specify region, it will try and read a credentials file.
About the SendEmail, this is the syntax that worked for me, I'd found another one also in the AWS docs site, and that one failed. It must've been for an older SDK.