Force.com-Toolkit-for-PHP icon indicating copy to clipboard operation
Force.com-Toolkit-for-PHP copied to clipboard

Could not connect to host

Open gabohm opened this issue 8 years ago • 8 comments
trafficstars

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

gabohm avatar May 03 '17 15:05 gabohm

Same problem for me, any idea @metadaddy ?

jeromegv avatar Oct 09 '17 15:10 jeromegv

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 avatar Oct 10 '17 12:10 jeromegv

@jeromegv I left Salesforce about 18 months ago and am no longer working on this. Not sure who owns this now - maybe @ReidCarlberg?

metadaddy avatar Oct 10 '17 21:10 metadaddy

@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

gabohm avatar Oct 11 '17 16:10 gabohm

@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 avatar Dec 18 '17 18:12 fernandoagostini

@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,

BuildBuilt avatar Apr 26 '18 07:04 BuildBuilt

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.

hatzopoulos avatar May 10 '18 16:05 hatzopoulos

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.

GreenBattery avatar Feb 02 '21 14:02 GreenBattery