Force.com-Toolkit-for-PHP
Force.com-Toolkit-for-PHP copied to clipboard
Could not connect to host
Hi, sometimes that I try to connect to Salesforce I have this error: Fatal error: Uncaught SoapFault exception: [HTTP] Could not connect to host in /Force/soapclient/SforceBaseClient.php:168 Stack trace: #0 [internal function]: SoapClient->__doRequest('<?xml version="...', 'https://login.s...', '', 1, 0) #1 Force/soapclient/SforceBaseClient.php(168): SoapClient->__call('login', Array) #2 Force/soapclient/SforceBaseClient.php(168): SoapClient->login(Array) #3 /home/donahoy/public_html/sincroniza/sincroniza.php(12): SforceBaseClient->login('universe...', '...') #4 {main} thrown in /Force/soapclient/SforceBaseClient.php on line 168
Same problem for me, any idea @metadaddy ?
I ended up doing something like that, which fixed it
$mode = array(
'ssl_method' => SOAP_SSL_METHOD_TLS,
'encoding'=>'UTF-8',
'cache_wsdl' => WSDL_CACHE_NONE,
'stream_context'=> stream_context_create(
array(
'ssl'=> array(
'crypto_method' => STREAM_CRYPTO_METHOD_TLSv1_2_CLIENT,
'ciphers' => 'SHA256',
'verify_peer'=>false,
'verify_peer_name'=>false,
'allow_self_signed' => true
)
)
)
);
$client->createConnection($partner_wsdl, null,$mode);
@jeromegv I left Salesforce about 18 months ago and am no longer working on this. Not sure who owns this now - maybe @ReidCarlberg?
@jeromegv thanks for your answer, I'll try the code. Where do you get this data? SOAP_SSL_METHOD_TLS WSDL_CACHE_NONE STREAM_CRYPTO_METHOD_TLSv1_2_CLIENT
@jeromegv Thanks for the code. Spent a few hours until I stumble upon your answer. All happen after updating PHP version. Had other problems (not SalesForce) because of "verify_peer" settings. Thanks again!
@fernandoagostini ..
Hi , right now I am facing problem that PHP is not able to connect to the HOST. Could you guide me on this ?
Best Regards,
I am pretty sure the HTTP connection simply failed, it happens. Could be SF, could be the requesting server, could be the network, a simple timeout due to congestion. You will need to detect it, and re-run your request. An example of this is Guzzle's retry-subscriber.
It's worth pointing out that @jeromegv 's response is very helpful, but it disables TLS security effectively as no certificate verification is done (making it vulnerable to MITM attacks). This may be okay in development environments but worth careful consideration for code that will be used in production.