pax_global_header00006660000000000000000000000064125415364070014521gustar00rootroot0000000000000052 comment=86074bf0fc2caf02ec8819a93f65a37cd0b44c8e php-invoker-1.1.4/000077500000000000000000000000001254153640700137665ustar00rootroot00000000000000php-invoker-1.1.4/.gitattributes000066400000000000000000000000171254153640700166570ustar00rootroot00000000000000*.php diff=php php-invoker-1.1.4/.gitignore000066400000000000000000000000731254153640700157560ustar00rootroot00000000000000/composer.lock /composer.phar /.idea /vendor /phpunit.xml php-invoker-1.1.4/LICENSE000066400000000000000000000030121254153640700147670ustar00rootroot00000000000000PHP_Invoker Copyright (c) 2011-2015, Sebastian Bergmann . All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. * Neither the name of Sebastian Bergmann nor the names of his contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. php-invoker-1.1.4/README.md000066400000000000000000000007151254153640700152500ustar00rootroot00000000000000# PHP_Invoker `PHP_Invoker` is an utility class for invoking callables with a timeout. ## Installation To add `PHP_Invoker` as a local, per-project dependency to your project, simply add a dependency on `phpunit/php-invoker` to your project's `composer.json` file. Here is a minimal example of a `composer.json` file that just defines a dependency on `PHP_Invoker` 1.1: { "require": { "phpunit/php-invoker": "1.1.*" } } php-invoker-1.1.4/build.xml000066400000000000000000000015571254153640700156170ustar00rootroot00000000000000 php-invoker-1.1.4/composer.json000066400000000000000000000015471254153640700165170ustar00rootroot00000000000000{ "name": "phpunit/php-invoker", "description": "Utility class for invoking callables with a timeout.", "type": "library", "keywords": [ "process" ], "homepage": "https://github.com/sebastianbergmann/php-invoker/", "license": "BSD-3-Clause", "authors": [ { "name": "Sebastian Bergmann", "email": "sebastian@phpunit.de", "role": "lead" } ], "support": { "issues": "https://github.com/sebastianbergmann/php-invoker/issues" }, "require": { "php": ">=5.3.3", "phpunit/php-timer": ">=1.0.6", "ext-pcntl": "*" }, "require-dev": { "phpunit/phpunit": "~4" }, "autoload": { "classmap": [ "src/" ] }, "autoload-dev": { "classmap": [ "tests/" ] } } php-invoker-1.1.4/phpunit.xml.dist000066400000000000000000000007221254153640700171420ustar00rootroot00000000000000 tests src php-invoker-1.1.4/src/000077500000000000000000000000001254153640700145555ustar00rootroot00000000000000php-invoker-1.1.4/src/Invoker.php000066400000000000000000000033571254153640700167130ustar00rootroot00000000000000 * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ declare(ticks = 1); /** * Utility class for invoking callables with a timeout. * * @since Class available since Release 1.0.0 */ class PHP_Invoker { /** * @var int */ protected $timeout; /** * Invokes a callable and raises an exception when the execution does not * finish before the specified timeout. * * @param callable $callable * @param array $arguments * @param int $timeout in seconds * @return mixed * @throws InvalidArgumentException */ public function invoke($callable, array $arguments, $timeout) { if (!is_callable($callable)) { throw new InvalidArgumentException; } if (!is_integer($timeout)) { throw new InvalidArgumentException; } pcntl_signal(SIGALRM, array($this, 'callback'), TRUE); pcntl_alarm($timeout); $this->timeout = $timeout; try { $result = call_user_func_array($callable, $arguments); } catch (Exception $e) { pcntl_alarm(0); throw $e; } pcntl_alarm(0); return $result; } /** * Invoked by pcntl_signal() when a SIGALRM occurs. */ public function callback() { throw new PHP_Invoker_TimeoutException( sprintf( 'Execution aborted after %s', PHP_Timer::secondsToTimeString($this->timeout) ) ); } } php-invoker-1.1.4/src/TimeoutException.php000066400000000000000000000005601254153640700205740ustar00rootroot00000000000000 * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ /** * @since Class available since Release 1.0.0 */ class PHP_Invoker_TimeoutException extends RuntimeException { } php-invoker-1.1.4/tests/000077500000000000000000000000001254153640700151305ustar00rootroot00000000000000php-invoker-1.1.4/tests/InvokerTest.php000066400000000000000000000030341254153640700201160ustar00rootroot00000000000000 * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ declare(ticks = 1); if (!defined('FIXTURE_PATH')) { define( 'FIXTURE_PATH', dirname(__FILE__) . DIRECTORY_SEPARATOR . '_fixture' . DIRECTORY_SEPARATOR ); } /** * Tests for PHP_Invoker. * * @since Class available since Release 1.0.0 */ class PHP_InvokerTest extends PHPUnit_Framework_TestCase { protected $callable; protected $invoker; protected function setUp() { $this->callable = new TestCallable; $this->invoker = new PHP_Invoker; } public function testCallableIsCorrectlyInvoked() { $this->assertTrue( $this->invoker->invoke(array($this->callable, 'test'), array(0), 1) ); } /** * @expectedException PHP_Invoker_TimeoutException */ public function testExceptionIsRaisedOnTimeout() { $this->invoker->invoke(array($this->callable, 'test'), array(2), 1); } /** * @expectedException InvalidArgumentException */ public function testExceptionIsRaisedOnInvalidCallable() { $this->invoker->invoke(NULL, array(), 1); } /** * @expectedException InvalidArgumentException */ public function testExceptionIsRaisedOnInvalidTimeout() { $this->invoker->invoke(array($this->callable, 'test'), array(), NULL); } } php-invoker-1.1.4/tests/_fixture/000077500000000000000000000000001254153640700167555ustar00rootroot00000000000000php-invoker-1.1.4/tests/_fixture/TestCallable.php000066400000000000000000000001661254153640700220300ustar00rootroot00000000000000