Is it possible to programmatically launch the php interactive shell from a file?

StackOverflow https://stackoverflow.com/questions/19361682

  •  30-06-2022
  •  | 
  •  

Pregunta

I would like to be able to either launch php in interactive mode via phing or via PHP (worst case scenario, phing can run an adhoc task with the desired code).

I've gotten this far:

<?php
  $cmd = 'php -d auto_prepend_file=bootstrap.php -a';
  passthru($cmd)

And the above almost gets me what I want. I enter a shell I can interact with, but the prompts are gone (the php > at the start of each line), all meta-commands (e.g., \>) totally fail, and typing exit; does nothing instead of exit the shell. So, as you can see, this isn't the ideal shell. Is this even possible without installing phpsh?

Thanks in advance.

¿Fue útil?

Solución

I think PsySH will give you want you want. It's a PHP REPL that gives you the option to configure it to automatically include a bootstrap file.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top