Functions.php 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. <?php
  2. declare(strict_types=1);
  3. /**
  4. * This file is part of Hyperf.
  5. *
  6. * @link https://www.hyperf.io
  7. * @document https://hyperf.wiki
  8. * @contact group@hyperf.io
  9. * @license https://github.com/hyperf/hyperf/blob/master/LICENSE
  10. */
  11. namespace Hyperf\Watcher;
  12. use RuntimeException;
  13. use Swoole\Coroutine\System;
  14. use function passthru;
  15. if (function_exists('exec')) {
  16. /**
  17. * @return mixed
  18. */
  19. function exec(string $command)
  20. {
  21. if (class_exists(System::class)) {
  22. return System::exec($command);
  23. }
  24. if (function_exists('\exec')) {
  25. \exec($command, $output, $code);
  26. $output = implode(PHP_EOL, $output);
  27. return compact('code', 'output');
  28. }
  29. if (function_exists('\passthru')) {
  30. ob_start();
  31. passthru($command, $code);
  32. $output = ob_get_clean();
  33. ob_end_clean();
  34. return compact('code', 'output');
  35. }
  36. throw new RuntimeException('No available function to run command.');
  37. }
  38. }