0

The constructor of the SOAP client in my wsdl web service is awfully slow, I get the response only after the fastcgi_read_timeout value in my Nginx config is reached, it seems as if the remote server is not closing the connection. I also need to set it to a minimum of 15 seconds otherwise I will get no response at all.

I already read similar posts here on SO, especially this one PHP SoapClient constructor very slow and it's linked threads but I still cannot find the actual cause of the problem.

This is the part which takes 15+ seconds:

$client = new SoapClient("https://apps.correios.com.br/SigepMasterJPA/AtendeClienteService/AtendeCliente?wsdl");

It seems as it is only slow when called from my php script, because the file opens instantly when accessed from one of the following locations:

  • wget from my server which is running the script
  • SoapUI or Postman (But I don't know if they cached it before)
  • opening the URL in a browser

Ports 80 and 443 in the firewall are open. Following the suggestion from another thread, I found two work arounds:

  • Loading the wsdl from a local file => fast
  • Enabling the wsdl cache and using the remote URL => fast

But still I'd like to know why it doesn't work with the original URL.

It seems as if the web service does not close the connection, or in other words, I get the response only after reaching the timeout set in my server config. I tried setting keepalive_timeout 15; in my Nginx config, but it does not work.

Is there any SOAP/PHP parameter which forces the server to close the connection?

Socrates
  • 189
  • 1
  • 5
  • 19

1 Answers1

1

I was able to reproduce the problem, and found the solution to the issue (works, maybe not the best) in the accepted answer of a question linked in the question you referenced:

PHP: SoapClient constructor is very slow (takes 3 minutes)

As per the answer, you can adjust the HTTP headers using the stream_context option.

$client = new SoapClient("https://apps.correios.com.br/SigepMasterJPA/AtendeClienteService/AtendeCliente?wsdl",array(
    'stream_context'=>stream_context_create(
        array('http'=>
            array(
                'protocol_version'=>'1.0',
                'header' => 'Connection: Close'
            )
        )
    )
));

More information on the stream_context option is documented at http://php.net/manual/en/soapclient.soapclient.php

I tested this using PHP 5.6.11-1ubuntu3.1 (cli)

Community
  • 1
  • 1
Ghassan Idriss
  • 2,120
  • 20
  • 16