PHP SoapClient SSL connection timeout error - php

While initiating a PHP SOAP client webservice I get these errors in production.
Here is the line of code which generates the error:
//the php soap server is at different server
$client = new SoapClient(SITE_ROOT . "locally hosted wsdl",
array("trace" => 1, "exception" => 1));
The error being generated is:
ERRNO: 2 \nTEXT: SoapClient::__doRequest() [<a href='soapclient.--dorequest'>soapclient.--dorequest</a>]: SSL: connection timeout \nLOCATION:
So these errors only occur in production and occur 2-3 % of the total requests.
Also this is a PHP SOAP over HTTPS webservice, also the server hosting the webservice has firewall but all our frontend servers have access through the firewall.
Also the default_socket_timeout is set to 60 secs and max execution time is 30 seconds.
My question:
I want to know why this is happening.

Try this:
$client=new SoapClient(
SITE_ROOT."your/wsdl.here.wsdl",
array(
"exceptions" => true,
"connection_timeout" => 60,
"style" => SOAP_RPC,
"use" => SOAP_ENCODED,
)
);
$mxResponse=$client->__soapCall(
"someFunctionName",
array("params", "here")
);

Related

php SoapClient fails to connect, but command line curl call works

I have a LAMP server (#1) that is communicating via soap with another server (#2) via WSDL. If I issue a curl call on the command line of server 1 to the URL of server 2, it works fine and get the appropriate WSDL response, but a php soapclient to the same URL is getting a "failed to load external entity" error. This was working before when we had a self signed certificate on server 2, but quit working about the same time we upgraded to a CA certificate.
Funny thing is this server is load balanced with another server at a different location (different OS, but same php code/database) and the second server isn't having any issues at all.
Here is the code I am using for the soap client:
function getSoapClient(){
ini_set("soap.wsdl_cache_enabled", 0);
// standard soap client for application service
$post_url = lum_getString("[CAMPAIGN_POST_URL]").
"?enterprise=".lum_getString("[CAMPAIGN_ENTERPRISE]").
"&company=".lum_getString("[CAMPAIGN_COMPANY]");
$options = array(
'trace' => true,
'cache_wsdl' => WSDL_CACHE_NONE,
'exceptions' => 1,
'verifypeer' => false,
'verifyhost' => false,
'allow_self_signed' => true,
'login' => lum_getString("[CAMPAIGN_POST_ID]"),
'password' => lum_getString("[CAMPAIGN_POST_LC]"),
);
$context = stream_context_create(
array(
'user_agent' => 'PHPSoapClient',
'ssl' => array(
'verify_peer' => false,
'allow_self_signed' => true,
),
'https' => array(
'curl_verify_ssl_peer' => false,
'curl_verify_ssl_host' => false,
)
)
);
$options['stream_context'] = $context;
$client = new SoapClient($post_url."&wsdl",$options);
return $client;
}
The curl and soapclient are using the same ports so it shouldn't be a firewall issue.
Any help in identifying the issue or helping me figure what is wrong is greatly appreciated.
Turns out it appears to be a firewall issue. I opened up all access from server 1 to server 2 and things started working. Not too sure what the issue was. I reduced the options to just the login and password, it's still working. Firewalls are often the answer.
Any ideas regarding the firewall, the correct ports, and why it wasn't working is much appreciated.
Why was cURL working and SOAP not?

cURL error 28: Resolving timed out after 5001 milliseconds

I use WordPress and I recently moved my site from the cpanel host to a Linux server with directadmin panel.
Right after the transfer realized that customers have the following error when downloading via EDD plugin.
cURL error 28: Resolving timed out after 5001 milliseconds
I also got this error of w3_total_cache plugin.
Server informatin:
Centos 6.8 (Final)
cURL 7.54.0 (Final)
directadmin
cURL error 28: Resolving timed out after 5001 milliseconds means DNS resolving failed.
so just change the DNS server list in /etc/resolv.conf.
or maybe we can bind the hostname and ip address in /etc/hosts.
this image shows the demo.
As reported here:
https://wordpress.org/support/topic/dropbox-upload-fails-with-curl-timeout-error/
You can apply this temporary fix to extend the HTTP request timeout:
add_filter( 'http_request_timeout', function( $timeout ) { return 60; });
Wordpress default is 5 seconds.
To resolve this you have to set the curl connection time out and time out value at the time of curl initialization.
Just changes this two property value.
CURLOPT_CONNECTTIMEOUT => 30,
CURLOPT_TIMEOUT => 60,
For more details check This.
update these two lines here:
/usr/share/icingaweb2/modules/jira/library/Jira/RestApi.php
$opts = array(
CURLOPT_URL => $this->url($url),
CURLOPT_HTTPHEADER => $headers,
CURLOPT_USERPWD => $auth,
CURLOPT_CUSTOMREQUEST => \strtoupper($method),
CURLOPT_RETURNTRANSFER => true,
CURLOPT_CONNECTTIMEOUT => 30,
CURLOPT_TIMEOUT => 30,
You can set
set_time_limit(120);
in the wp-config.php after the MySQL settings section.

SoapClient "Could not connect to host" exception with one WSDL API

I have a problem with one WSDL connection with API, after moving to a new OVH VPS machine, so it's maybe some kind of strange misconfiguration.
Other WSDL that I use with SoapClient, work fine, without problems. I'm able to use file_get_contents on the address, but when I use SoapClient I gives a exception "Could not connect to host", when trying to use a procedure from that API.
Any ideas? I've tried some stream_context with some SSL options. What's the funniest, on the other OVH VPS is working fine.
System is Debian 8 with PHP 5.6.19 onboard.
Addresss of the WSDL is here: https://api-test.paczkawruchu.pl/WebServicePwR/WebServicePwRTest.asmx?WSDL
After consultation with WSDL provider, and checking logs on both sides, we found the anwser. It looks like PHP 5.6 have some problems, and you have to change parameters to SOAP 1.2. This resolved finally the problem. Resolution could be found here, in first comment:
SOAP PHP fault parsing WSDL: failed to load external entity?
// options for ssl in php 5.6.5
$opts = array(
'ssl' => array('ciphers'=>'RC4-SHA', 'verify_peer'=>false, 'verify_peer_name'=>false)
);
// SOAP 1.2 client
$params = array ('encoding' => 'UTF-8', 'verifypeer' => false, 'verifyhost' => false, 'soap_version' => SOAP_1_2, 'trace' => 1, 'exceptions' => 1, "connection_timeout" => 180, 'stream_context' => stream_context_create($opts) );
$oSoapClient = new SoapClient ( $url . "?WSDL", $params );

SSL23_GET_SERVER_HELLO:sslv3 alert handshake failure Paypal adaptive payment

The bellow is my curl config of PPHttpConfig.php for paypal adaptive payment SDK,
public static $DEFAULT_CURL_OPTS = array(
CURLOPT_SSLVERSION => 4,
CURLOPT_CONNECTTIMEOUT => 10,
CURLOPT_RETURNTRANSFER => TRUE,
CURLOPT_TIMEOUT => 60, // maximum number of seconds to allow cURL functions to execute
CURLOPT_USERAGENT => 'PayPal-PHP-SDK',
CURLOPT_HTTPHEADER => array(),
CURLOPT_SSL_VERIFYHOST => 2,
CURLOPT_SSL_VERIFYPEER => FALSE,
CURLOPT_SSL_CIPHER_LIST => 'TLSv1',
);
But,getting error
Type PayPal\Exception\PPConnectionException
Message error:14077410:SSL
routines:SSL23_GET_SERVER_HELLO:sslv3 alert handshake failure
OpenSSL error messages tend towards cryptic and generic.
The most common causes for this error are that
the server certificate has expired
the server cerificate is invalid
the client and server can not negotiate a protocol level or cipher acceptable to both parties.
Your version of OpenSSL is relatively recent (but still out of date / containing serious vulnerabilities). I'd like to think that PayPal wouldn't let their certificates expire.
Less common reasons for seeing this error are
your database is CA certs is out of date
CACert database can't be found (is your PHP running in a chroot?)
you've got some silly entries in your openssl.cnf or it can't be found
you are sitting behind a MITM proxy you didn't know about
You didn't say where the PHP is running, what its running on, nor what acces you have to the machine. If it's a Linux box and you have shell access, you might want to see what happens when you probe the server from the command line.

Error in cURL request: name lookup timed out

I wrote some code that fill a login form and submit it via post method. Like:
$config = array(
'adapter' => 'Zend_Http_Client_Adapter_Curl',
);
$this->siteObj = new Zend_Http_Client('http://example.com', $config);
$this->siteObj->setCookieJar();
$this->siteObj->setUri('http://example.com/login');
$this->siteObj->setParameterPost( 'data[User][name]', 'user' );
$this->siteObj->setParameterPost( 'data[User][password]', 'password' );
$response = $this->siteObj->request('POST');
its works fine, but some times this error occur:
Error in cURL request: name lookup timed out
Error: An Internal Error Has Occurred.
whats the problem? what can I do to solve it?
I encountered the same problem:
From the shell, curl worked.
From the shell, the PHP script worked.
PHP could not ping the website.
The DNS config was right.
After restarting Apache, it worked. So strange.
It can be a timeout problem.
Try adjusting the connection timeout:
$config = array(
'adapter' => 'Zend_Http_Client_Adapter_Curl',
'timeout' => 100
);
you can also set single curl options:
$config = array(
'adapter' => 'Zend_Http_Client_Adapter_Curl',
'curloptions' => array(
CURLOPT_USERAGENT => 'Zend_Curl_Adapter',
CURLOPT_HEADER => 0,
CURLOPT_VERBOSE => 0,
CURLOPT_RETURNTRANSFER => 1,
CURLOPT_TIMEOUT => 10,
CURLOPT_SSL_VERIFYPEER => false,
),
);
If you find out that it is a timeout issue, I would not suggest to increase too much the timeout parameter, but rather to make a for loop with a number of retries.
It means that your DNS server failed to return a response in time. Check your DNS configuration (e.g. /etc/resolv.conf on Linux), and make sure they are alive and functional. Also try to ping the host in the URL from the same sever to get an idea whether the problem only in PHP or the any application running on the server (more likely).

Categories