1

I am trying to force PHP to NEVER try to connect and send information to a webservice over a set period of time. I am using below and for some reason it will run over the time allowed and I can't figure out why. For example if I set it to 30 seconds, I will see that it takes a lot longer in some cases. I need to figure out a way to 100% kill connection if it takes too long.

TIA, Will

    $intTimeout = $this->getTimeout();
        $client = new SoapClient("{$this->url}?WSDL", array('trace' => 0, 'connection_timeout'=>$intTimeout));
        try {
            $this->response = $client->someService($objPerson);
        }
        catch(Exception $e) {

        }
        $this->restoreTimeout();

    function getTimeout()
    {
        $intTimeout = @$this->timeout ? $this->timeout : 60;
        $_SESSION['old_sock'] = ini_get('default_socket_timeout');
        ini_set('default_socket_timeout', $intTimeout);

        return $intTimeout;
    }

    function restoreTimeout()
    {
        $intCurSockTime = @$_SESSION['old_sock'];
        if($intCurSockTime) ini_set('default_socket_timeout', $intCurSockTime);
    }
user550574
  • 53
  • 4

1 Answers1

0

the problem is: default_socket_timeout is counting before socket responds, as long as it gets response, it will wait forever.

this is a good example using curl with timeout as fallback: http://www.darqbyte.com/2009/10/21/timing-out-php-soap-calls/

similar question: PHP SoapClient Timeout

Community
  • 1
  • 1
Kevin
  • 1,232
  • 10
  • 28