package.xml0000664000076400007640000000465111707342061011006 0ustar sbsb PHP_Invoker pear.phpunit.de Utility class for invoking callables with a timeout. Utility class for invoking callables with a timeout. Sebastian Bergmann sb sb@sebastian-bergmann.de yes 2012-01-23 1.1.0 1.1.0 stable stable BSD License http://github.com/sebastianbergmann/php-invoker/blob/master/README.markdown 5.2.7 1.9.4 PHP_Timer pear.phpunit.de 1.0.1 pcntl PHP_Invoker-1.1.0/PHP/Invoker/Autoload.php0000664000076400007640000000523011707342061015767 0ustar sbsb. * 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. * * @package PHP * @subpackage Invoker * @author Sebastian Bergmann * @copyright 2011-2012 Sebastian Bergmann * @license http://www.opensource.org/licenses/bsd-license.php BSD License * @link http://github.com/sebastianbergmann/php-timer * @since File available since Release 1.0.0 */ function php_invoker_autoload($class = NULL) { static $classes = NULL; static $path = NULL; if ($classes === NULL) { $classes = array( 'php_invoker' => '/Invoker.php', 'php_invoker_timeoutexception' => '/Invoker/TimeoutException.php' ); $path = dirname(dirname(__FILE__)); } if ($class === NULL) { $result = array(__FILE__); foreach ($classes as $file) { $result[] = $path . $file; } return $result; } $cn = strtolower($class); if (isset($classes[$cn])) { require $path . $classes[$cn]; } } spl_autoload_register('php_invoker_autoload'); PHP_Invoker-1.1.0/PHP/Invoker/TimeoutException.php0000664000076400007640000000471111707342061017527 0ustar sbsb. * 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. * * @package PHP * @subpackage Invoker * @author Sebastian Bergmann * @copyright 2011-2012 Sebastian Bergmann * @license http://www.opensource.org/licenses/bsd-license.php BSD License * @link http://github.com/sebastianbergmann/php-invoker * @since File available since Release 1.0.0 */ /** * @package PHP * @subpackage Invoker * @author Sebastian Bergmann * @copyright 2011-2012 Sebastian Bergmann * @license http://www.opensource.org/licenses/bsd-license.php BSD License * @version Release: 1.1.0 * @link http://github.com/sebastianbergmann/php-invoker * @since Class available since Release 1.0.0 */ class PHP_Invoker_TimeoutException extends RuntimeException { } PHP_Invoker-1.1.0/PHP/Invoker.php0000664000076400007640000000743211707342061014225 0ustar sbsb. * 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. * * @package PHP * @subpackage Invoker * @author Sebastian Bergmann * @copyright 2011-2012 Sebastian Bergmann * @license http://www.opensource.org/licenses/bsd-license.php BSD License * @link http://github.com/sebastianbergmann/php-invoker * @since File available since Release 1.0.0 */ /** * Utility class for invoking callables with a timeout. * * @package PHP * @subpackage Invoker * @author Sebastian Bergmann * @copyright 2011-2012 Sebastian Bergmann * @license http://www.opensource.org/licenses/bsd-license.php BSD License * @version Release: 1.1.0 * @link http://github.com/sebastianbergmann/php-invoker * @since Class available since Release 1.0.0 */ class PHP_Invoker { /** * @var integer */ 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 integer $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.0/ChangeLog.markdown0000664000076400007640000000032211707342061015032 0ustar sbsbPHP_Invoker 1.1 =============== This is the list of changes for the PHP_Invoker 1.1 release series. PHP_Invoker 1.1.0 ----------------- * `PHP_Invoker_TimeoutException` now holds information on the timeout. PHP_Invoker-1.1.0/LICENSE0000664000076400007640000000301111707342061012442 0ustar sbsbPHP_Invoker Copyright (c) 2011, 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.0/README.markdown0000664000076400007640000000215111707342061014142 0ustar sbsbPHP_Invoker =========== Utility class for invoking callables with a timeout. Installation ------------ PHP_Invoker should be installed using the [PEAR Installer](http://pear.php.net/). This installer is the backbone of PEAR, which provides a distribution system for PHP packages, and is shipped with every release of PHP since version 4.3.0. The PEAR channel (`pear.phpunit.de`) that is used to distribute PHP_Invoker needs to be registered with the local PEAR environment: sb@ubuntu ~ % pear channel-discover pear.phpunit.de Adding Channel "pear.phpunit.de" succeeded Discovery of channel "pear.phpunit.de" succeeded This has to be done only once. Now the PEAR Installer can be used to install packages from the PHPUnit channel: sb@vmware ~ % pear install phpunit/PHP_Invoker downloading PHP_Invoker-1.0.0.tgz ... Starting to download PHP_Invoker-1.0.0.tgz (2,536 bytes) ....done: 2,536 bytes install ok: channel://pear.phpunit.de/PHP_Invoker-1.0.0 After the installation you can find the PHP_Invoker source files inside your local PEAR directory; the path is usually `/usr/lib/php/PHP`. package.sig0000664000076400007640000000030611707342067010767 0ustar sbsb-----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.11 (GNU/Linux) iEYEABECAAYFAk8dxDcACgkQaGfFFLhbXWkUxgCeObpo7GaFBgNF+6mMVHJGJnt+ VmQAnRw+X7q7goON/++yQYQo8G/Rf5xG =2HdT -----END PGP SIGNATURE-----