I have some code that connects to a newsletter service via SOAP. It works with no problem on our dev server, but on our live server it doesn't work at all. It's not returning any errors; just a blank white page. I've put some error_logs into the code and found exactly where it stops working - on the line creating the new SoapClient. Is there some kind of server config that needs to be set? Our code is identical between dev and prod, so the only thing I can figure is a server issue. (Note that the first chunk of code below was provided by the newsletter service, not written by me.)
# bronto API session/connection setup
ini_set("soap.wsdl_cache_enabled", "0");
date_default_timezone_set('America/Chicago');
$wsdl = "https://api.bronto.com/v4?wsdl";
$url = "https://api.bronto.com/v4";
/*error log statements up to this point return what is expected;
an error log after the following line (starting with $client = new SoapClient)
does not get triggered at all. */
$client = new SoapClient($wsdl, array('trace' => 1, 'encoding' => 'UTF-8'));
$client->__setLocation($url);
$token = "XXX";
$sessionId = $client->login(array("apiToken" => $token))->return;
$client->__setSoapHeaders(array(new SoapHeader("http://api.bronto.com/v4",
'sessionHeader',
array('sessionId' => $sessionId))));
I've also tried something like this to explicitly see any errors, but no luck - still nothing in the error log.
try {
$client = #new SoapClient($wsdl, array('trace' => 1, 'encoding' => 'UTF-8'));
}
catch (SoapFault $E) {
error_log($E->faultstring) ;
}
error_log("ok");
I would check the installed PHP packages on the dev server and compare to the Prod server. fr2.php.net/manual/en/soap.setup.php
This will more than likly be a config setup for php on the live server, but here are the common problems i have had with SOAP on php,
First thing is check the allowed memory for php on live comparable with dev (SOAP is big and bad for memory)
Is the php on the live server the same version as the dev server,
Is the live server authorized to access the SOAP server (if auth is used on an IP Level)
as one of the SOAP packages i have used did this to me i found out there was a version mismatch, last but not least could you tell us what SOAP Library if any other then php default your using so we can help as your code looks good :)
thinking about it have you install soap i don't think php natively supports it i think its a pear or pecl package and if your using XAMPP or easyPHP on dev these have all of both all ready included in php.
Related
I've been trying for days to get Google's Calendar PHP API working on my local Laravel development site. Here's the problem:
I'm using a service account so I can perform functions on one calendar (the service accounts calendar). I'm not authenticating users and requesting access to their calendar.
I've verified everything from my client ID, the service email address, the key.P12 file, still nothing happens.
Here is my code:
$key = File::get($this->key);
$credentialObj = new \Google_Auth_AssertionCredentials(
$this->serviceAccountName,
array('https://www.googleapis.com/auth/calendar'),
$key,
'notasecret'
);
$client = new \Google_Client();
$client->setApplicationName($this->applicationName);
$client->setClientId($this->clientId);
$client->setAssertionCredentials($credentialObj);
\session_start();
$calendarServiceObj = new \Google_Service_Calendar($client);
$events = $calendarServiceObj->events->listEvents('mygmail#gmail.com');
dd($events->getItems());
I've even tried using Google's own example here:
https://github.com/google/google-api-php-client/blob/master/examples/service-account.php
No errors, nothing. Just a blank error page every single time. I've tried so many examples all over the internet, even here on stack overflow, and at the end, all I get is a 'This webpage is not available'. This happens on every browser.
Laravel is set to development mode so all errors are displayed, and I've even force set the ini using ini_set("display_errors", 1);.
I know everything works fine up until I request anything from the service object. All the calendar api's are set to on in my developer account. Does my local development domain need to have SSL enabled?
It be so nice if I could figure out at least what is going on, but with this obscure error, I have no idea.
If anyone has any tips, I'd really appreciate it. Thanks!!
EDIT: I've scoured through googles API code, and this is exactly where the request fails:
vendor\google\apiclient\src\Google\Signer\P12.php
Line 77 to 92:
public function sign($data)
{
if (version_compare(PHP_VERSION, '5.3.0') < 0) {
throw new Google_Auth_Exception(
"PHP 5.3.0 or higher is required to use service accounts."
);
}
$hash = defined("OPENSSL_ALGO_SHA256") ? OPENSSL_ALGO_SHA256 : "sha256";
//If I die(); here, I receive the response
if (!openssl_sign($data, $signature, $this->privateKey, $hash)) {
//Something happens here, or inside the openssl_sign command, I never reach the exception
throw new Google_Auth_Exception("Unable to sign data");
}
//It never reaches here
return $signature;
}
In my PHP Info:
Solved by updating PHP. I was using Softaculous AMPPs 2.3 with PHP 5.4.27. Upgrading to AMPPs 2.6 fixed the issue. My Open SSL in my config is now:
Nothing was done to my code above since, and it now works. This was definitely an open ssl issue. Anyone receiving an ERR_CONNECTION_RESET must update their open_ssl version.
I hope this helps anyone trying to figure this out.
I hope someone can help me because I am looking for the solution since 2 working days...
I have a php website which need to request a distant webservice.
When I try it on my computer (Win7 + WAMP), it works well.
When I try it on the webserver (CentOs6), it return me the following error :
SOAP-ERROR: Parsing WSDL: Couldn't load from
'http://ip_address:8080/gss-0.1/FileUtilities?wsdl' : failed to load
external entity "http://ip_address:8080/gss-0.1/FileUtilities?wsdl"
NB: the webservice is on the same network of my webserver (I do not use the same IP/port).
I know that the WSDL is accessible from the webserver because it is accessible using curl linux function.
curl http://ip_address:8080
My php code is:
<?php
$wsdl = "http://ip_address:8080/gss-0.1/FileUtilities?wsdl";
try{
$client = new SoapClient($wsdl ,array('trace' => 1,
'exceptions'=> 1,
'cache_wsdl' => WSDL_CACHE_NONE
));
}
catch(Exception $e) {
echo $e->getMessage();
}?>
OK I found a solution but I don't understand the problem...
So I execute this Linux command
setsebool -P httpd_can_network_connect on
And now all is running !
Response here: Thanks to user2533111
If its not firewalled there at your web server and its working in your local but not at your webserver(CentOS). its might be a case of different PHP version and php.ini settings.
Can you compare your PHP version and those below extensions in your CentOs server with your WAMP at local.
S0AP,
php_openssI,
openssI,
curI;
IMPORTANT EDIT: Found out that issue is caused by my web server (I don't know how to fix that) - tags changed. I use latest XAMPP.
I am trying to set up server to server connection with Google Analytics API with OAuth following this guide:
Service Applications and Google Analytics API V3: Server-to-server OAuth2 authentication?
I have following code:
require_once 'google-api-php-client/src/Google_Client.php';
require_once 'google-api-php-client/src/contrib/Google_AnalyticsService.php';
// create client object and set app name
$client = new Google_Client();
$client -> setApplicationName("------------"); // name of your app
// set assertion credentials
$client->setAssertionCredentials(
new Google_AssertionCredentials(
"------------#developer.gserviceaccount.com", // email you added to GA
array('https://www.googleapis.com/auth/analytics.readonly'),
file_get_contents("-:/-----------/-----/------/----/---------------------------------------------------.p12") // keyfile you downloaded
));
// other settings
$client->setClientId("------------.apps.googleusercontent.com"); // from API console
$client->setAccessType('offline_access'); // this may be unnecessary?
// create service and get data
$service = new Google_AnalyticsService($client);
$ids = "ga:--------";
$startDate = "2013-05-01";
$endDate = "2013-05-26";
$metrics = "ga:visitors";
var_dump($service->data_ga->get($ids, $startDate, $endDate, $metrics));
Which causes HTTP error #101 (ERR_CONNECTION_RESET). My issue is similar to: Service Applications and Google Analytics API V3: Error 101 (net::ERR_CONNECTION_RESET) but I have no other calls to Google_AnalyticsService().
I have PHP version 5.4.7 (XAMPP version) with enabled OpenSSL (enabled via uncommeting line in php.ini).
Thank you in advance for any answers. How to deal with ones like this (producing some HTTP error and stopping? Are there logs that produce any useful informations?)?
EDIT: Copying code from post: "Not sufficient permissions" google analytics API service account to me causes same error (no other messages printed).
I found way to deal with this issue. It's caused by Apache and PHP together - they use different version of OpenSSL.
First workaround (one that does not work for me as I write it 05-28-3013) on XAMPP 1.8.1 (release date 30.9.2012) is to replace files ssleay32.dll and libeay32.dll within Apache /bin/ folder with these from php folder. It does not work for me because mod_ssl can't work with PHP's DLLs.
Second workaround is to install other package. Personally, I switched to ZendServer which has synced versions of OpenSSL and Apache.
Of course you can always build your own Apache and PHP making sure you have OpenSSL and mod_ssl cooperating and in latest version.
Hi everyone I'm cracking my head over this for two weeks already.
The problem is that I made a soap service which seems to work alright. When I ask it to show it's functions it returns them all etc. But when I try to invoke two functions to the server I get an segfault error:
'[notice] child pid 13950 exit signal Segmentation fault (11)'
But when I invoke the two functions seperately they work. I googled for this for a week and tried different wsdl formats but the only thing that came up was a possible php bug or some error in the wsdl (which seems unlikely because my validator can't find errors).
The browser gives me this in response:
Error 324 (net::ERR_EMPTY_RESPONSE)
I'm currently running php version 5.3.6 and also tried 5.2.17 to try to eliminate the possible php bug. But they both gave the same error.
Nobody over here at the office knows how to fix this because 'everything should be alright'.
Could anyone get me in the right direction?
The client:
(this code gives the apache crash)
ini_set('soap.wsdl_cache_enabled', 0);
ini_set('soap.wsdl_cache_ttl', 0);
try{
$soap = new SoapClient("http://localhost/virtueleincasso.wsdl", array("exceptions" => 1));
$password = $soap->virtuele_incasso_login('user', 'pass');
$status = $soap->get_status($password , 1060);
}catch (SoapFault $exception){
echo $exception->faultstring;
}
The server:
ini_set('soap.wsdl_cache_enabled', 0);
ini_set('soap.wsdl_cache_ttl', 0);
$server = new SoapServer(DIR_ROOT."/virtueleincasso.wsdl");
$server->setClass('PP_Api');
$server->handle();
die();
SOLUTION: I used a die function to stop the server function returning an empty string. I fixed it by changing this to an exit function.
I had a similar problem with multiple PHP processes using the soap extension. It seems to be a bug in the way WSDL caching is handled. I also tried disabling it with ini_set() calls as you have without success. I eventually found a workaround in my case. I needed to set the cache_wsdl option to WSDL_CACHE_NONE.
return new SoapClient("http://localhost/virtueleincasso.wsdl", array(
"exceptions" => 1,
"cache_wsdl" => WSDL_CACHE_NONE
));
I am writing some php code for interfacing with a magento server and am trying to group my soap calls.
The magento wiki suggests the use of SoapClient::multiCall and I am able to get that to work fine on my home machine.
But If I try the exact same code on my server it tells me:
SoapFault exception: [Client] Function ("multiCall") is not a valid method for this service
The php manual for SoapClient doesn't even list multiCall as a method.
My home machine is running php version: PHP 5.3.3While the server is running version: PHP 5.2.14
I'm at a loss for what's happening here any help would be appreciated.
Here is the code I'm running:
$client = new SoapClient($wsdl_location);
$session = $client->login($user, $pass);
$client->multiCall($session, array(
array(catalog_category.currentStore),
array(catalog_category.currentStore)
)
);
Well I feel like a fool, it was a problem with the WSDL.
I was using different WSDLs on my home machine and server.
When I changed the URL from:
http://yourmagentohost/api/v2_soap?wsdl=1
to:
http://yourmagentohost/magento/api/?wsdl
You'll notice that I didn't have the /magento/ in my original URL.