Is there anyway for a SoapClient Request to time out and throw an exception. As of now, I get PHP Server response timeout, in my case 60 seconds. Basically what I want is, if there isn't any reply from the Web Service within certain time, an exception would be thrown and I could catch it. The 60 seconds warning is not what I want.
相关问题
- Views base64 encoded blob in HTML with PHP
- Laravel Option Select - Default Issue
- PHP Recursively File Folder Scan Sorted by Modific
- Can php detect if javascript is on or not?
- Using similar_text and strpos together
While Andrei linked to a decent solution, this one has less code yet arrives at a good solution:
Example code:
And there is also the stream context, if you need more fine-grained HTTP control. See the
stream_context
option fornew SoapClient()
Docs. Under the surfaceSoapClient
uses the HTTP and SSL transports.I am using the following logic when working with SOAPClient:
This helps me to wait up to 10 seconds for connection establishment, and 60 seconds for the call execution.
Have a look at
if you are comfortable and your environment allows you to extend classes.
It basically extends the
SoapClient
class, replaces the HTTP transport with curl which can handle the timeouts:The accepted answer will break all functionalities that SoapClient has to offer. Like setting the correct content headers, authentication etc.
This would be a better solution to the problem
You can install this through composer: https://github.com/ideaconnect/idct-soap-client
It extends the standard SoapClient and gives options to set the amount of retries, connection and read timeouts.