Skip to content

Commit 75e756c

Browse files
authored
Merge pull request #34 from clue-labs/timeouts
Support timeouts for SOAP requests (HTTP timeout option)
2 parents 2ff8b0d + 2114cd7 commit 75e756c

File tree

3 files changed

+61
-3
lines changed

3 files changed

+61
-3
lines changed

README.md

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ This project provides a *simple* API for invoking *async* RPCs to remote web ser
4141
* [Functions](#functions)
4242
* [Promises](#promises)
4343
* [Cancellation](#cancellation)
44+
* [Timeouts](#timeouts)
4445
* [Install](#install)
4546
* [Tests](#tests)
4647
* [License](#license)
@@ -325,6 +326,43 @@ $loop->addTimer(2.0, function () use ($promise) {
325326
});
326327
```
327328

329+
#### Timeouts
330+
331+
This library uses a very efficient HTTP implementation, so most SOAP requests
332+
should usually be completed in mere milliseconds. However, when sending SOAP
333+
requests over an unreliable network (the internet), there are a number of things
334+
that can go wrong and may cause the request to fail after a time. As such,
335+
timeouts are handled by the underlying HTTP library and this library respects
336+
PHP's `default_socket_timeout` setting (default 60s) as a timeout for sending the
337+
outgoing SOAP request and waiting for a successful response and will otherwise
338+
cancel the pending request and reject its value with an Exception.
339+
340+
Note that this timeout value covers creating the underlying transport connection,
341+
sending the SOAP request, waiting for the remote service to process the request
342+
and receiving the full SOAP response. To pass a custom timeout value, you can
343+
assign the underlying [`timeout` option](https://github.com/clue/reactphp-buzz#timeouts)
344+
like this:
345+
346+
```php
347+
$browser = new Browser($loop);
348+
$browser = $browser->withOptions(array(
349+
'timeout' => 10.0
350+
));
351+
352+
$client = new Client($browser, $wsdl);
353+
$proxy = new Proxy($client);
354+
355+
$proxy->demo()->then(function ($response) {
356+
// response received within 10 seconds maximum
357+
var_dump($response);
358+
});
359+
```
360+
361+
Similarly, you can use a negative timeout value to not apply a timeout at all
362+
or use a `null` value to restore the default handling. Note that the underlying
363+
connection may still impose a different timeout value. See also the underlying
364+
[`timeout` option](https://github.com/clue/reactphp-buzz#timeouts) for more details.
365+
328366
## Install
329367
330368
The recommended way to install this library is [through Composer](https://getcomposer.org).

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
},
1616
"require": {
1717
"php": ">=5.3",
18-
"clue/buzz-react": "^2.0 || ^1.3",
18+
"clue/buzz-react": "^2.5",
1919
"react/event-loop": "^1.0 || ^0.5 || ^0.4 || ^0.3",
2020
"react/promise": "^2.1 || ^1.2",
2121
"ext-soap": "*"

tests/FunctionalTest.php

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -141,9 +141,10 @@ public function testBlzServiceWithInvalidMethod()
141141
}
142142

143143
/**
144-
* @expectedException Exception
144+
* @expectedException RuntimeException
145+
* @expectedExceptionMessage cancelled
145146
*/
146-
public function testCancelMethodRejects()
147+
public function testCancelMethodRejectsWithRuntimeException()
147148
{
148149
$api = new Proxy($this->client);
149150

@@ -153,6 +154,25 @@ public function testCancelMethodRejects()
153154
Block\await($promise, $this->loop);
154155
}
155156

157+
/**
158+
* @expectedException RuntimeException
159+
* @expectedExceptionMessage timed out
160+
*/
161+
public function testTimeoutRejectsWithRuntimeException()
162+
{
163+
$browser = new Browser($this->loop);
164+
$browser = $browser->withOptions(array(
165+
'timeout' => 0
166+
));
167+
168+
$this->client = new Client($browser, self::$wsdl);
169+
$api = new Proxy($this->client);
170+
171+
$promise = $api->getBank(array('blz' => '12070000'));
172+
173+
Block\await($promise, $this->loop);
174+
}
175+
156176
public function testGetLocationForFunctionName()
157177
{
158178
$this->assertEquals('http://www.thomas-bayer.com/axis2/services/BLZService', $this->client->getLocation('getBank'));

0 commit comments

Comments
 (0)