Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 11916
  • Last Modified:

Problem with "default_socket_timeout"

hi,

I recently started having issues with response times from a Web Service I use.
The responses were taking over 2 minutes at times to come back whereas normally they are less than a second.

i tried adding the folliwng to my scripts...

ini_set('default_socket_timeout', 15);

but this has had absolutely no effect. also, is the default not 60 seconds?

any help would be appreciated

thanks
0
Fatlog
Asked:
Fatlog
  • 3
  • 3
1 Solution
 
rhickmottCommented:
Its normally 60s yes but I cant recall whether the 30s default script execution time kicks in or not.

It all depends where the problem lies. How are you recalling data? socket_timeout only applies to connecting sockets however if the socket connects but the server is not sending anything then the stream can sit there until the script times out.

How are you requesting the data?
0
 
FatlogAuthor Commented:
they are all SOAP connections using soapClient() in PHP 5. I connect to the Web Service Endpoint and then make a request to one of the API methods and wait for the response.

The connection to the Web Service is fine. the problem occurs when callinag a specific API method. 99.9% of the time it works fine. i might call this method a 1000 times a day and only a handful will encounter this problem.

i accept that i may encounter probelms connecting to web services at times, however i would like to timeout on the request after 10 to 15 seconds if i haven't gotten a response.

0
 
rhickmottCommented:
Ah well the soapClient is a seperate class ( pear/pcl ? ) it will prob have its own methods for setting stream/socket timeouts which will override anything you set in your php.

socket_timeout applies to sockets opened by you.

A quick bit of google shows that this appears to be a undocumented parameter.

$client = new SoapClient($wsdl, array("connection_timeout"=>5));

Basically wherever you call the Soap Class it takes in an array of parameters just add the "connection_timeout" to it and see if that works.


0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
FatlogAuthor Commented:
thanks for the swift replies!

the soapClient class is part of PHP 5.
i have specified the connection as you recommend; however, this does not do what you would expect it to!

this is from the PHP manual(http://ie.php.net/soap-soapclient-construct), which i looked up when i started to encounter this error...

################################################################################
The connection_timeout option defines a timeout in seconds for the connection to the SOAP service. This option does not define a timeout for services with slow responses. To limit the time to wait for calls to finish the default_socket_timeout setting is available.
################################################################################

so the timeout only handles the initial connectio to the SOAP service and not subsequent calls to slow services.
When i found this i then implemented the suggested 'default_socket_timeout' which does not appear to have any affect on slow services!?!?



0
 
rhickmottCommented:
Is suspect the soap class will set its own time-outs and script timeouts. You would prob have to go delving though the code of the class itself and follow it though to find out where and when it sets its timeouts.

Most scripts will ini_set their own time-out and then reset it as the class terminates to ensure that you dont get problems with code or settings in other classes. they really should have made this settable though.
0
 
FatlogAuthor Commented:
hhhmmm,

sorry about the delay in getting back to this question.
this problem seems to have been sorted without me doing anything new.

the 'default_socket_timeout' seems to work now. no idea why it wasn't before - unless the problem wasn't with that!??!

anyway. all is good now.
0

Featured Post

Vote for the Most Valuable Expert

It’s time to recognize experts that go above and beyond with helpful solutions and engagement on site. Choose from the top experts in the Hall of Fame or on the right rail of your favorite topic page. Look for the blue “Nominate” button on their profile to vote.

  • 3
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now