Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Calling CallFire using PHP Soap (PHP v5) 1

Status
Not open for further replies.

fletchsod

Programmer
Dec 16, 2002
181
Hi! I'm trying to call the CallFire webservice using PHP SOAP and it is not working. It's my first time calling the webservice in PHP. Sample script below...

Code:
$wsdl = "[URL unfurl="true"]https://www.callfire.com/service/PredictiveService?wsdl";[/URL]
$client1 = new SoapClient($wsdl);

That doesn't work as I got this error...

--snip--
PHP Fatal error: SOAP-ERROR: Parsing WSDL: Couldn't load from " failed to load external entity " in /home/callfire/CampaignCreate.php on line 85
--snip--

After reading the documentation, I tried this one...

Code:
$wsdl = "[URL unfurl="true"]https://www.callfire.com/service/PredictiveService?wsdl";[/URL]
$client1 = new SoapClient($wsdl, array("location" => "[URL unfurl="true"]https://www.callfire.com/service/PredictiveService",[/URL] "uri" => "???");

But I have a problem. What are the example of location's value and uri's value should I entered for the non-WSDL to work properly?

Thanks...
 
with this code
Code:
<?php
$client = new soapclient('[URL unfurl="true"]https://www.callfire.com/service/PredictiveService?wsdl');[/URL]
echo '<pre>';
print_r($client->__getFunctions());
?>


I get this result
Code:
Array
(
    [0] => getConnectionForAgentResponse getConnectionForAgent(getConnectionForAgent $parameters)
    [1] => answeringMachineTransferStoreAgentResponseResponse answeringMachineTransferStoreAgentResponse(answeringMachineTransferStoreAgentResponse $parameters)
    [2] => updateRatioResponse updateRatio(updateRatio $parameters)
    [3] => loginAgentResponse loginAgent(loginAgent $parameters)
    [4] => createCallCenterConnectCampaignResponse createCallCenterConnectCampaign(createCallCenterConnectCampaign $parameters)
    [5] => sendAgentCallBackWithMusicSettingResponse sendAgentCallBackWithMusicSetting(sendAgentCallBackWithMusicSetting $parameters)
    [6] => getSingleAgentStatsResponse getSingleAgentStats(getSingleAgentStats $parameters)
    [7] => storeAgentResponseResponse storeAgentResponse(storeAgentResponse $parameters)
    [8] => sendAgentCallBackResponse sendAgentCallBack(sendAgentCallBack $parameters)
    [9] => isAgentLoggedInResponse isAgentLoggedIn(isAgentLoggedIn $parameters)
    [10] => getAgentStatsResponse getAgentStats(getAgentStats $parameters)
    [11] => createCallCenterConnectCampaignWithAMResponse createCallCenterConnectCampaignWithAM(createCallCenterConnectCampaignWithAM $parameters)
)

which I suspect is exactly as expected.
 
What I got instead is ...

[message:protected] => SoapClient::SoapClient(): 'location' and 'uri' options are required in nonWSDL mode
[string:Exception:private] =>
[code:protected] => 0
[file:protected] => /home/callfire
[line:protected] => 8
[previous:Exception:private] =>
[faultstring] => SoapClient::SoapClient(): 'location' and 'uri' options are required in nonWSDL mode
[faultcode] => Client
[faultcodens] =>
 
then you are running in non-wsdl mode. which should not be possible if you are reproducing my code precisely.

try forcibly disabling the cache by adding this as the first line of your script.

Code:
ini_set('soap.wsdl_cache_enabled', false);
 
Reverting back to original script with both different ini_set() options.

Code:
//ini_set('soap.wsdl_cache_enabled', false);
ini_set('soap.wsdl_cache_enabled', 0);

$client = new soapclient('[URL unfurl="true"]https://www.callfire.com/service/PredictiveService?wsdl');[/URL]

Still get the same error. So, why is PHP running in non-wsdl mode?

Thanks...
 
I have just tried this on another box - using your code. it works fine.

thus the issue is specific to your installation and not generic or with the remote service.

what version of php are you running? have you upgraded and patched your php installation? have you restarted your webserver to flush the cache?
 
also make sure that you delete any cache remnants manually after the restart. they should be in /tmp or wherever the soap cache directory is (see your phpinfo for precise details).
 
I'm using PHP version 5.3.2 and I'm using PHP Shell Script as there is no installed webserver on this machine.

Okay, cleared the soap and session files in /tmp directory and tried again. Same error. :-/

Is there something about configure or compiling I should be aware of, regarding the PHP Soap, that may result in having it not working?

Thanks...
 
i have had big problems with php 5.3+ and downgraded all my installations to 5.2.x. one serious flaw is the problem with implicit flush - but this should be unrelated to your issues.

having said that, i have just upgraded my imac (via apple) and find that the command line version of php is 5.3.1. using your script (and print_r($client)) I still get the anticipated result.

there are a few runtime configurations to be aware of. they all relate to cacheing so once you have deleted all the cache files and turned the cache off, none should be pertinent.

so I can see no reason why your script does not work.

so let's try another method (with thanks to the comments in the php manual )

Code:
<?php
ini_set('soap.wsdl_cache_enabled', false);
$url = '[URL unfurl="true"]https://www.callfire.com/service/PredictiveService?wsdl';[/URL]
$wsdl = get_wsdl($url); 
$client = new SoapClient($wsdl); 
print_r($client);

function gTempDir(){
	return sys_get_temp_dir();
}

function get_wsdl($url) { 
    clearstatcache();
    $cache_file = gTempDir() . DIRECTORY_SEPARATOR . "soap.wsdl." . md5($url); 
	$ch = curl_init($url);
	$options = array(
						CURLOPT_FOLLOWLOCATION=>true,
						CURLOPT_FRESH_CONNECT=>true,
						CURLOPT_RETURNTRANSFER=>true,
						CURLOPT_SSL_VERIFYPEER=>false,
						CURLOPT_USERAGENT=>"Mozilla/4.0 (compatible; MSIE 5.01; Windows NT 5.0)");
	curl_setopt_array($ch, $options);
	$data = curl_exec($ch);
	curl_close($ch);
	file_put_contents($cache_file, $data);
    return $cache_file; 
} 
?>
 
>PHP Fatal error: SOAP-ERROR: Parsing WSDL:...
I have no problem doing that even on a php 5.3vc6. (There are some version-related grieve mentioned out there.) One thing I would try first is to use the ip address in place of dn.
>$wsdl = "[ignore][/ignore]";
[tt]$wsdl = "[ignore][/ignore]";[/tt]
see if it can go beyond that line.
 
that's a good point. if the OP has not correctly set up DNS on his server then that might well cause the fatal error.
 
Resolving " to IP-Address works just fine on this AIX machine. When I ran the "nslookup command line, I got the IP Address result.

I added the "get_wsdl()" function and I got an interesting result. See below...

//With " hostname in wsdl variable...
//(cURL works great & generated data got dumped into the "/tmp" directory...
//PHP soap result below...
Code:
Internal Soap Error: SoapFault exception: [HTTP] Could not connect to host in /home/callfire/test.php:118
Stack trace: 
#0 [internal function]: SoapClient->__doRequest('<?xml version="...', '[URL unfurl="true"]https://www.cal...',[/URL] '', 1, 0)
#1 [internal function]: SoapClient->__call('createCallCente...', Array)
#2 /home/callfire/test.php(118): SoapClient->createCallCenterConnectCampaign(Array)
#3 {main}

//With "67.159.185.148" hostname in wsdl variable...
//(cURL seems to work or failed & generated no data that got dumped into the "/tmp" directory... The file size is 0 bytes...
//PHP soap result below...
Code:
PHP Fatal error: SOAP-ERROR: Parsing WSDL: Couldn't load from '/tmp/soap.wsdlda41d1cbc1cd0da69dc5c6a1034791b0' : Start tag expected, '<' not found in /home/callfire/test.php on line 111
PHP Fatal error: Uncaught SoapFault exception: [WSDL] SOAP-ERROR: Parsing WSDL: Couldn't load from '/tmp/soap.wsdlda41dlcbc1cd0da69dc5c6a103479lb0' : Start tag expected, '<' not found in /home/callfire/test.php:111
Stack trace:
#0 /home/callfire/test.php(111): SoapClient->SoapClient('/tmp/soap.wsdl...', Array)
#1 {main} thrown in /home/callfire/test.php on line 111

Sigh! Nothing is ever simple or works...
 
it sounds as though you are being blocked from getting data externally. is it possible that your host is blocking external https access? if the curl method is failing then we are left with a small number of scenarios:

1. your host is blocking external access
2. your IP is being blocked by the remote server
3. something in your php installation is completely fubar'd

i'd go for item 1 as the most likely now. the 0byte file size of $cache_file indicates that there is nothing being returned from the curl request. it is possible that headers are being returned though. we could check for that ...

Code:
function get_wsdl($url) { 
    clearstatcache();
    $cache_file = gTempDir() . DIRECTORY_SEPARATOR . "soap.wsdl." . md5($url); 
    $ch = curl_init($url);
    $options = array(
                        CURLOPT_FOLLOWLOCATION=>true,
                        CURLOPT_FRESH_CONNECT=>true,
                        CURLOPT_RETURNTRANSFER=>true,
                        CURLOPT_SSL_VERIFYPEER=>false,
                        CURLOPT_HEADER=>true,
                        CURLOPT_USERAGENT=>"Mozilla/4.0 (compatible; MSIE 5.01; Windows NT 5.0)");
    curl_setopt_array($ch, $options);
    $data = curl_exec($ch);
    curl_close($ch);
    file_put_contents($cache_file, $data);
    echo 'outputting received data: <br/><pre>' . htmlspecialchars($data).'</pre><br/>';
    return $cache_file; 
}


this will output the result of the curl request to the browser window.
 
wsdl is freely available to the public and can be saved as a local copy. The problem is if you refer it as a local copy, would the parsing error persists?
 
When I did the cURL verbose using the callfire's ip-address, i got this error message

--snip--
"SSL: certificate subject name '*.callfire.com' does not match target host name '67.159.195.148'"
--snip--

So, i looked up at php.net and it said I need to use "CURLOPT_SSL_VERIFYHOST=>false", must be a newer version thingie...

So, I tried again with "CURLOPT_SLL_VERIFYHOST=>false" and now I got a different error message.

Code:
Internal Soap Error: SoapFault exception: [HTTP] Could not connect to host in /home/callfire/test.php:119
Stack trace:
#0 [internal function]: SoapClient->__doRequest('<?xml version="...', '[URL unfurl="true"]https://67.159....',[/URL] '', 1, 0)
#1 [internal function]: SoapClient->__call('createCallCente...', Array)
#2 /home/callfire/test.php(119): SoapClient->createCallCenterConnectCampaign(Array)
#3 {main}

So, both error now matched regarding of using " and "67.159.185.148". They both point to Soap error message "[HTTP] Could not connect to host in ....".

This now confirm jpadie's #1 and #2 likely cause of problem.

Alright, this will take a while to figure out how to get it working on AIX cuz the internet access is not being blocked. :-/ Thanks for all you do.
 
Um... I'm not sure if this will do the trick...


-snip--
By the way thanks everyone for the help with this After removing the generic error codes I came up with this error

Fatal error: Uncaught SoapFault exception: [HTTP] Could not connect to host in /home/eye123/public_html/track.php:44 Stack trace: #0 [internal function]: SoapClient->__doRequest(’<?xml version=”...’, ‘ ‘track’, 1, 0) #1 [internal function]: SoapClient->__call(’track’, Array) #2 /home/eye123/public_html/track.php(44): SoapClient->track(Array) #3 {main} thrown in /home/eye123/public_html/track.php on line 44

Then after a couple of days of trying to figure out what this error was and trying different soap call constructs I decided that it was not the code and turned to my soap install After recompiling soap with the following below I got everything to work


So thanks everyone for the help and input


—enable-soap’ ‘—enable-sockets’ ‘—enable-wddx’ ‘—

soap
Soap Client enabled
Soap Server enabled

Directive Local Value Master Value
soap.wsdl_cache 1 1
soap.wsdl_cache_dir /tmp /tmp
soap.wsdl_cache_enabled 1 1
soap.wsdl_cache_limit 5 5
soap.wsdl_cache_ttl 86400 86400
--snip--
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top