I've implemented a mail delivery service using SparkPost for a website. The code looks like this:
require '/vendor/autoload.php';
use SparkPost\SparkPost; use GuzzleHttp\Client;
use Ivory\HttpAdapter\Guzzle6HttpAdapter;
$httpAdapter = new Guzzle6HttpAdapter(new Client());
$sparky = new SparkPost($httpAdapter, ['key'=>'...']);
[...]
[...]
$results = $sparky->transmission->send($mailarray);
It works just fine locally on WampServer, however when I deploy it to Azure it does not. I don't have access to Azure logs, but I managed to narrow down the problem to one line:
$sparky = new SparkPost($httpAdapter, ['key'=>'...']);
I simply get a 500 error without any other explanation. The weird thing is when I wrap it around a try/catch, I still don't get anything other than a blank screen and a 500 on the console. I suspect it has to do something with /autoload.php not being able to load something.
Any thoughts?
According the requirement of SparkPost lib on Github repo at https://github.com/SparkPost/php-sparkpost/blob/master/composer.json#L18, it need PHP version higher than 5.5. So you can modify the PHP version of your Azure Web Apps, please refer to https://azure.microsoft.com/en-us/documentation/articles/web-sites-php-configure/#how-to-change-the-built-in-php-version for detail steps.
Related
I'm trying to work with the Google Cloud Vision API with PHP. I created my first test page and when run from a website, the PHP works correctly with no issues. I have a new twist on my project and I want to run the same PHP code from the terminal.
The issue I'm having now though is that I get an error that my script doesn't have the credentials loaded.
Here is the code I'm using to load my credentials file that works in my website version...
putenv('GOOGLE_APPLICATION_CREDENTIALS=Credential-file.json');
This doesn't work on my Terminal run version of the code. So I've tried a couple other options like...
putenv('GOOGLE_APPLICATION_CREDENTIALS=/Full/Path/To/Credential-file.json');
and
$_ENV['GOOGLE_APPLICATION_CREDENTIALS'] = "/Full/Path/To/Credential-file.json";
The exact error is...
PHP Fatal error: Uncaught DomainException: Could not load the default credentials. Browse to https://developers.google.com/accounts/docs/application-default-credentials for more information in /Library/WebServer/Documents/google_vision/vendor/google/auth/src/ApplicationDefaultCredentials.php:156
My question is... Is there a better way to load the credentials file when I'm trying to run my PHP from the terminal? Or what mistake am I making in my version?
I should mention that I'm running this on MacOS with the Google Cloud client libraries.
Any help/suggestions would be greatly appreciated.
Thanks in advance!
The error message indicates that the variable is not set properly (as opposed to it being set to an invalid path).
putenv only lasts the duration of the current script. Setting values on $_ENV does not make them available to getenv, the method used by the Google auth library. Are you setting the credentials environment variable within the same script you're executing?
You can provide the value in the invocation as well:
GOOGLE_APPLICATION_CREDENTIALS=/path/to/keyfile.json php my-script.php
Or set the variable in your terminal session:
export GOOGLE_APPLICATION_CREDENTIALS=/path/to/keyfile.json
php my-script.php
If you're using Google\Cloud\Vision\V1\ImageAnnotatorClient, you can authenticate with a keyfile directly:
use Google\Cloud\Vision\V1\ImageAnnotatorClient;
$vision = new ImageAnnotatorClient([
'credentials' => '/path/to/keyfile.json
]);
Or with Google\Cloud\Vision\VisionClient:
use Google\Cloud\Vision\VisionClient;
$vision = new VisionClient([
'keyFilePath' => '/path/to/keyfile.json'
]);
I use quickbooks-php. If I want to get a Quickbooks tax rate (not in the online US account). I'm looking for error
QuickBooks_Loader::load(): Failed opening required '/var/www/project/addons/quickbooks/vendor/consolibyte/quickbooks/QuickBooks/IPP/Object/EffectiveTaxRate.php'
I use 3.2 version in composer
"consolibyte/quickbooks": "3.2",
As I understand this file there are only in dev version.
When I switch to the development version everything is fine.
In 3.3 version the same error.
Waiting for reply. Thank you.
Code what i use
$service = new QuickBooks_IPP_Service_TaxCode();
return $service->query(self::getQB()->getContext(), self::getQB()->getRealm(), "SELECT * FROM TaxCode");
When I added it file (from dev version EffectiveTaxRate.php) to the vendor/consolibyte/quickbooks/QuickBooks/IPP/Object/, all is well but it is not a solution to the problem, after the composer update the problem will come back.
You noted the solution in your post:
As I understand this file there are only in dev version. When I switch to the development version everything is fine.
Use the development version until a new release is made which contains the file you need.
I have a Restler-powered API (api.example.com) and I have a website for developers (developer.example.com). My aim is to be able to explore the API from the latter site.
But as I add this to the API Explorer options: discoveryUrl:"http://api.example.com/resources.json" it doesn't work (displays "0 : error http://api.example.com/resources.json") even though these facts:
discoveryUrl:"../resources.json" works well from api.example.com/explorer
discoveryUrl:"http://api.example.com/resources.json" is OK from api.example.com/explorer
http://api.example.com/resources.json works just fine from the browser!
Could you tell me what can be the cause of this issue?
This is because of the browser that is restricting javascript not to load a remote resource without proper permission
Read more about Cross-origin resource sharing from the Wikipedia
In order to enable cross domain access, enable crossOriginResourceSharing on your api server as shown in the following example
use Luracast\Restler\Restler;
use Luracast\Restler\Defaults;
require_once "../../../vendor/restler.php";
Defaults::$crossOriginResourceSharing = true;
$r = new Restler();
$r->addAPIClass('MinMax');
$r->addAPIClass('MinMaxFix');
$r->addAPIClass('Type');
$r->addAPIClass('Resources');
$r->handle();
Above example is live in http://restler3.luracast.com/tests/param/resources.json you may want to try that from your remote explorer
I have an issue with obtaining data from Windows Azure's runtime using the newest (at the time of writing) PHP SDK from Github. Here is a test I am running on one of our hosted services:
<?php
include 'WindowsAzure/WindowsAzure.php';
use \WindowsAzure\ServiceRuntime\RoleEnvironment;
use \WindowsAzure\ServiceRuntime\Internal\RoleEnvironmentNotAvailableException;
try {
echo RoleEnvironment::getDeploymentId();
}
catch (RoleEnvironmentNotAvailableException $Exception) {
die('Failed to find deployment id');
}
RoleEnvironmentNotAvailableException is always thrown. Looking at the source, it seems to try sending commands through a named pipe (\.\pipe\WindowsAzureRuntime). Do I need to specify something within my ServiceConfiguration.csdef/cscfg in order to have access to this named pipe?
Any advice would be most welcome!
Got confirmation from MS EMEA Developer Support that current SDK does not support this function. They suggested similar workaround to jonnu above - use the previous SDK's functionality for role environment / configuration settings.
The ServiceRuntime APIs run only on Cloud so if this code snippet runs on local machine it'll throw an exception as you've pointed out. Further, if you want to debug your ServiceRuntime code you've to deploy your service to WA then use remote desktop connection to access the cloud machine and debug your code.
I am looking for help with this problem and I hope someone give me that help. The error is the following:
Fatal error: SOAP-ERROR: Parsing WSDL: Couldn't load from 'http://example.com/index.php/api/?wsdl' : failed to load external entity "http://example.com/index.php/api/?wsdl" in
/var/www/presentacion/app/code/local/Pengo/Extension/Model/Something.php on line 28
And the code that I'm using to connect to it is something like this:
$this->_soap = new SoapClient(http://example.com/index.php/api/?wsdl);
and there is where it says is the error.
I have been serching in Google, PHP forums, here in StackOverflow and Magento itself but I don't find the solution anywhere.
What I had seen is that the WSDL is never get parsed or loaded as the error says and none of its functions.
I tried connecting like this:
$options['location'] = http://example.com/index.php/api/?wsdl;
$options['uri'] = 'urn:Magento';
$this->_soap = new SoapClient(null, $options);
like this it doesn't dispatch any error like the others but there aren't functions to use, like in the other case it doesnt' load and parse the WSDL.
I am a bit frustrated because I have been developing this like 1 month and now that I am making some tests it shows this message, I had test it when it was really empty and new and it worked fine.
So any help would be appreciated.
Thank you.
Nine times out of ten this error is Magento is telling you it can't load the WSDL file. Magento is telling you this. It's not your local client code that's complaining.
Magento uses the PHP SoapServer object to create its SOAP API. The SoapServer object needs to access the WSDL as well. Try running the following from your server's command line
curl http://example.com/index.php/api/?wsdl
If I'm right, the above will timeout/fail.
Because of some quirks in DNS, it's surprisingly common that a server won't be able to access itself via its domain name. If this is the case, the quickest fix is adding an entry to the server's hosts file. (Talk to your server admin if none of that made sense)
Well after all the things that I test the only one that worked for me, I don't know why but it worked, was doing this in two separate machines. I tried that because I read that somewhere and I just do it and my Magento and Webservice now works perfectly. Whenever I try to do this local it dispatch the same error.
I hope this can help someone in the future and they don't have to knock their head on the wall because of this problem.
Thank you all for your answers and comments.
Alan Storm is right on the Money here!
Make sure that you check your server Hosts File, and that it includes an entry for both domain and www.domain. Espicialy important if you are doing server rewrites.