Reputation: 15253
I'm new to PHP. After lots of search I managed to somehow use my web service that is created by Java with PHP but the problem is the constructor of SoapClient class is very slow. Here's my PHP code:
<?
require_once('SOAP/Client.php');
$url = "http://127.0.0.1:8024/_RS?wsdl";
$sc = new SoapClient($url);
?>
This takes up to 3 minutes some times. I don't know what the problem is. After creating the constructor I could use it in a for
loop for 50 times in 1 second so I'm pretty sure that the constructor is the part that is slowing down my code.
What do you think is causing the problem?
Thank you in advance.
PS: More information in my other question: https://stackoverflow.com/questions/5929669/call-a-wsdl-web-service-created-by-java-from-nushphere-phped
PPS: As suggested by AJ, I used XDebug and kcachegrind to analyze the problem. As you can see, I was right. Here's the picture:
Upvotes: 2
Views: 6498
Reputation: 154
I have the same problem. The php SoapClient is very fast with the same webservice deployed on Tomcat. I tried doing a "wget" to see if the headers in the response was different and as the problem is with the WSDL caching the difference I found might be the reason:
With Tomcat:
HTTP/1.1 200 OK
Server: Apache-Coyote/1.1
Content-Type: text/xml;charset=utf-8
Content-Length: 23925
Date: Thu, 08 Mar 2012 23:13:10 GMT
Connection: keep-alive
With Endpoint.publish(...)
HTTP/1.1 200 OK
Content-type: text/xml;charset=utf-8
Content-length: 23837
Now I just need to find out how to force the Endpoint.publish(...)
to insert a Server
, Date
, or Connection
-header.
(Edit) I found a solution: The issue is not only with Chunked data but with "Keep-Alive". This can be prevented by setting the header "Connection: Close" in a stream_context. Please see below:
class ImprovedSoapClient extends SoapClient
{
public function __construct($wsdlLocation)
{
parent::__construct(
$wsdlLocation
, array(
, 'cache_wsdl' => WSDL_CACHE_NONE
, 'stream_context'=>stream_context_create(
array('http'=>
array(
'protocol_version'=>'1.0'
, 'header' => 'Connection: Close'
)
)
)
)
);
}
}
Upvotes: 4
Reputation: 804
This looks pretty similar to your problem: http://www.ozonesolutions.com/programming/2011/05/nsclient-login-time/ Its using php toolkit instead of java, but the solution may still apply.
Upvotes: 1
Reputation: 28174
I would guess that it's not the constructor of the PHP class, but instead it's probably making the first call to your Java Web service - before any objects have been initialized on the Java application.
But, you should determine this for sure by using a PHP profiling tool, like Xdebug:
http://www.xdebug.org/docs/profiler
Upvotes: 1