note 97095 modified in soapclient.soapclient by danbrown

From: Date: Thu, 01 Apr 2010 13:40:40 +0000
Subject: note 97095 modified in soapclient.soapclient by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-167622@lists.php.net to get a copy of this message
I found that WSDL fetching fails when using basic authentication in the soapclient. So I implemented the following workaround using wget. I realize wget may not be an option for some environments, in that case cURL would be the next simplest thing. <?php $wsdl = get_wsdl("https://example.com/soap/service?wsdl"); $this->client = new SoapClient($wsdl, array('user'=>'someuser', 'password'=>'somepassword')); private function get_wsdl($url) { global $g; $url = escapeshellarg($url); $cache_file = "/tmp/soap.wsdl." . md5($url); //only fetch a new wsdl every hour if(!file_exists($cache_file) || filectime($cache_file) < time() - 3600) { $agent = escapeshellarg("--user-agent={$g['useragent']}"); mwexec("wget --quiet --timeout=5 {$agent} --no-check-certificate --output-document={$cache_file} {$url}"); if(!file_exists($cache_file)) { throw new Exception("Couldn't load WSDL at {$url}"); } } return $cache_file; } ?> --was-- I found that WSDL fetching fails when using basic authentication in the soapclient. The fix noted here (http://nl3.php.net/manual/en/ref.soap.php#41068) didn't work for me, so I implemented the following workaround using wget. I realize wget may not be an option for some environments, in that case cURL would be the next simplest thing. $wsdl = get_wsdl("https://somehost.com/soap/service?wsdl"); $this->client = new SoapClient($wsdl, array('user'=>'someuser', 'password'=>'somepassword')); private function get_wsdl($url) { global $g; $url = escapeshellarg($url); $cache_file = "/tmp/soap.wsdl." . md5($url); //only fetch a new wsdl every hour if(!file_exists($cache_file) || filectime($cache_file) < time() - 3600) { $agent = escapeshellarg("--user-agent={$g['useragent']}"); mwexec("wget --quiet --timeout=5 {$agent} --no-check-certificate --output-document={$cache_file} {$url}"); if(!file_exists($cache_file)) { throw new Exception("Couldn't load WSDL at {$url}"); } } return $cache_file; } http://php.net/manual/en/soapclient.soapclient.php

« previous php.notes (#167622) next »