Skip to content

Commit 4aa173e

Browse files
Store information about the timeout in PHP_Invoker_TimeoutException.
1 parent 6561731 commit 4aa173e

File tree

3 files changed

+25
-8
lines changed

3 files changed

+25
-8
lines changed

ChangeLog.markdown

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
PHP_Invoker 1.0
1+
PHP_Invoker 1.1
22
===============
33

4-
This is the list of changes for the PHP_Invoker 1.0 release series.
4+
This is the list of changes for the PHP_Invoker 1.1 release series.
55

6-
PHP_Invoker 1.0.0
6+
PHP_Invoker 1.1.0
77
-----------------
88

9-
* Initial release.
9+
* `PHP_Invoker_TimeoutException` now holds information on the timeout.

PHP/Invoker.php

+13-1
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,11 @@
5959
*/
6060
class PHP_Invoker
6161
{
62+
/**
63+
* @var integer
64+
*/
65+
protected $timeout;
66+
6267
/**
6368
* Invokes a callable and raises an exception when the execution does not
6469
* finish before the specified timeout.
@@ -82,6 +87,8 @@ public function invoke($callable, array $arguments, $timeout)
8287
pcntl_signal(SIGALRM, array($this, 'callback'), TRUE);
8388
pcntl_alarm($timeout);
8489

90+
$this->timeout = $timeout;
91+
8592
try {
8693
$result = call_user_func_array($callable, $arguments);
8794
}
@@ -101,6 +108,11 @@ public function invoke($callable, array $arguments, $timeout)
101108
*/
102109
public function callback()
103110
{
104-
throw new PHP_Invoker_TimeoutException;
111+
throw new PHP_Invoker_TimeoutException(
112+
sprintf(
113+
'Execution aborted after %s',
114+
PHP_Timer::secondsToTimeString($this->timeout)
115+
)
116+
);
105117
}
106118
}

package.xml

+8-3
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,10 @@
1717
<email>[email protected]</email>
1818
<active>yes</active>
1919
</lead>
20-
<date>2011-11-22</date>
20+
<date>2012-01-23</date>
2121
<version>
22-
<release>1.0.1</release>
23-
<api>1.0.0</api>
22+
<release>1.1.0</release>
23+
<api>1.1.0</api>
2424
</version>
2525
<stability>
2626
<release>stable</release>
@@ -56,6 +56,11 @@
5656
<pearinstaller>
5757
<min>1.9.4</min>
5858
</pearinstaller>
59+
<package>
60+
<name>PHP_Timer</name>
61+
<channel>pear.phpunit.de</channel>
62+
<min>1.0.1</min>
63+
</package>
5964
<extension>
6065
<name>pcntl</name>
6166
</extension>

0 commit comments

Comments
 (0)