diff --git a/src/Command/ReloadCommand.php b/src/Command/ReloadCommand.php new file mode 100644 index 000000000..8d1854b4e --- /dev/null +++ b/src/Command/ReloadCommand.php @@ -0,0 +1,62 @@ +setName('reload') + ->setAliases(['reload!']) + ->setDefinition([]) + ->setDescription('Reload the current session.') + ->setHelp( + <<<'HELP' +Reload the current session. + +Note: The PCNTL extension is required for reload to work. + +e.g. +>>> reload +HELP + ); + } + + /** + * {@inheritdoc} + */ + protected function execute(InputInterface $input, OutputInterface $output) + { + if (!function_exists('pcntl_exec')) { + throw new RuntimeException('Unable to reload session (PCNTL is required).'); + } + + $output->writeln('Reloading...'); + + if (!defined('PHP_BINARY')) { + throw new RuntimeException('Unable to identify PHP binary path.'); + } + + pcntl_exec(PHP_BINARY, $_SERVER['argv']); + } +} diff --git a/src/Shell.php b/src/Shell.php index 7d64c504b..82d96b59d 100644 --- a/src/Shell.php +++ b/src/Shell.php @@ -196,6 +196,7 @@ protected function getDefaultCommands() new Command\BufferCommand(), new Command\ClearCommand(), new Command\EditCommand($this->config->getRuntimeDir()), + new Command\ReloadCommand(), // new Command\PsyVersionCommand(), $sudo, $hist,