DEPRECATED: recommended to use symfony/process instead.
A PHP library for executing shell commands with an optional timeout., (*1)
DEPRECATED: This library is no longer being actively maintained. symfony/process has all the features of Hiatus and more. It is recommended as an alternative., (*2)
PHP 5.4 or newer is the only requirement for this library., (*3)
This package uses composer so you can just add
nubs/hiatus
as a dependency to your composer.json
file or execute the
following command:, (*4)
composer require nubs/hiatus
Composer's autoloader will automatically include the namespaced functions for use in your project., (*5)
Here's an example of how to execute a simple command:, (*6)
<?php // Get the directory listing of the directory given by the user. // NOTE: This is probably not a good idea to let users run arbitrary directory // listings. list($exitStatus, $stdout, $stderr) = \Hiatus\exec('ls -l', [$_POST['dir']]); if ($exitStatus !== 0) { throw new Exception('Command failed.'); } echo $stdout;
Including a timeout is simple:, (*7)
<?php // Download the url given by the user, but fail if it takes more than 10 // seconds. // NOTE: This is probably not a good idea to let users download arbitrary urls. list($exitStatus, $stdout, $stderr) = \Hiatus\exec( 'curl', [$_POST['url']], 10 ); if ($exitStatus !== 0) { throw new Exception('Command failed.'); } echo $stdout;
An exception-generating variant is also included:, (*8)
<?php try { list($stdout, $stderr) = \Hiatus\execX('ls /foo'); } catch (Exception $e) { echo "Error occurred: {$e->getMessage()}\n"; exit(1); } echo $stdout;
Both exec
and execX
can be given a string to pass on stdin:, (*9)
<?php list($exitStatus, $stdout, $stderr) = \Hiatus\exec( 'wc -c', [], null, 'stdin test' ); if ((int)$stdout !== 10) { echo "Well, this is awkward.\n"; }
Any changes, suggestions, or bug reports are welcome to be submitted on github. Pull requests are encouraged!, (*10)
This project is licensed under the MIT License., (*11)