package.xml 0000664 0000764 0000764 00000004651 11707342061 011006 0 ustar sb sb
PHP_Invokerpear.phpunit.deUtility class for invoking callables with a timeout.Utility class for invoking callables with a timeout.Sebastian Bergmannsbsb@sebastian-bergmann.deyes2012-01-231.1.01.1.0stablestableBSD License
http://github.com/sebastianbergmann/php-invoker/blob/master/README.markdown
5.2.71.9.4PHP_Timerpear.phpunit.de1.0.1pcntl
PHP_Invoker-1.1.0/PHP/Invoker/Autoload.php 0000664 0000764 0000764 00000005230 11707342061 015767 0 ustar sb sb .
* 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.php 0000664 0000764 0000764 00000004711 11707342061 017527 0 ustar sb sb .
* 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.php 0000664 0000764 0000764 00000007432 11707342061 014225 0 ustar sb sb .
* 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.markdown 0000664 0000764 0000764 00000000322 11707342061 015032 0 ustar sb sb PHP_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/LICENSE 0000664 0000764 0000764 00000003011 11707342061 012442 0 ustar sb sb PHP_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.markdown 0000664 0000764 0000764 00000002151 11707342061 014142 0 ustar sb sb PHP_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.sig 0000664 0000764 0000764 00000000306 11707342067 010767 0 ustar sb sb -----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.11 (GNU/Linux)
iEYEABECAAYFAk8dxDcACgkQaGfFFLhbXWkUxgCeObpo7GaFBgNF+6mMVHJGJnt+
VmQAnRw+X7q7goON/++yQYQo8G/Rf5xG
=2HdT
-----END PGP SIGNATURE-----