LinuxCommandLibrary

psysh

Debug and interactively experiment with PHP code

TLDR

Open a shell in the current directory

$ psysh
copy

Open a shell in a specific directory
$ psysh --cwd [path/to/directory]
copy

Use a specific configuration file
$ psysh --config [path/to/file]
copy

SYNOPSIS

psysh [options]

PARAMETERS

--help, -h
    Display help for the current command.

--version, -V
    Display this application version.

--config=<path>
    Specify a path to a custom PsySH config file.

--ansi
    Force ANSI output.

--no-ansi
    Disable ANSI output.

--verbose, -v|vv|vvv
    Increase the verbosity of messages: 1 for normal output, 2 for more verbose output and 3 for debug.

--quiet, -q
    Do not output any message.

--raw
    Raw output.

DESCRIPTION


Psysh is a powerful runtime developer console, also known as a REPL (Read-Eval-Print Loop), for PHP.

It provides an interactive command-line environment where PHP code snippets can be executed directly, variable states can be inspected, and documentation can be looked up. Psysh is an invaluable tool for rapid prototyping, debugging, and exploring PHP libraries and frameworks. It goes beyond a simple `php -a` by offering advanced features like a `ls` command for inspecting objects, `doc` for documentation, a built-in debugger, and the ability to extend its functionality with custom commands. It helps developers understand their code's runtime behavior without the need to modify files or reload web servers.

CAVEATS


Psysh is primarily a development and debugging tool and should not be used in production environments. Its interactive nature and access to the application's runtime state pose security risks if exposed.

While powerful, it requires a working PHP installation and Composer for typical installation.

<B>KEY FEATURES</B>


Psysh offers a rich set of features including:
- Variable inspection: Use `ls` to inspect variables, objects, and scope.
- Documentation lookup: `doc` command to read PHP manual pages directly.
- Code execution: Execute arbitrary PHP code in the current context.
- Built-in debugger: Step through code, set breakpoints, and inspect the call stack.
- Customizable: Extensible with custom commands and configuration.
- Intelligent output: Pretty-prints arrays and objects for readability.

<B>INSTALLATION</B>


Psysh is most commonly installed globally via Composer, the PHP package manager: `composer global require psy/psysh:@stable`. It can also be added as a development dependency to a project.

<B>CONFIGURATION</B>


Psysh can be configured via a `.psysh.php` file in the user's home directory or the project root, allowing customization of settings, commands, and tab completion.

HISTORY


Psysh was created by Justin Hileman and first released around 2013-2014. It emerged as a response to the need for a more sophisticated and feature-rich interactive PHP console, similar to those available in other languages like Ruby (IRB) or Python. Before Psysh, PHP developers often relied on `php -a` (the basic interactive mode) or print statements for debugging. Psysh quickly gained popularity within the PHP community for its advanced features, ease of use, and extensibility, becoming a de-facto standard for interactive PHP development.

SEE ALSO

php(1), irb(1), python(1), node(1)

Copied to clipboard