Certainly! Here’s a detailed answer for your Laracasts forum question:
Solution:
psysh is the underlying REPL (Read-Eval-Print Loop) used by Laravel Tinker, which is an interactive shell for Laravel. By default, psysh is only invoked when you explicitly run Tinker via the command line:
php artisan tinker
Laravel does not invoke psysh for job queues, scheduled tasks, HTTP requests, or any other background processes. It is strictly an interactive developer tool.
Why Might psysh Be Running?
If you see a psysh process running and using a lot of memory, here are a few possibilities:
-
A Tinker Session Was Started and Left Open:
If someone started a Tinker session (possibly in a detached terminal or background process) and never exited, thepsyshprocess would remain running. -
Automated Scripts or Debugging:
Rarely, someone might automate or script Tinker sessions for debugging, but this is not common or recommended. -
Misconfigured Supervisor or Process Manager:
If you use a process manager (like Supervisor) and accidentally configured it to runphp artisan tinker, it would keeppsyshrunning. -
Web-based Tinker Packages:
Some packages (like spatie/laravel-web-tinker) allow running Tinker via the browser. If left open, these can spawnpsyshprocesses.
How to Troubleshoot
- Check Who Started the Process:
Useps aux | grep psyshto see the user and command line that started the process. - Check Process Tree:
Usepstree -porps -ef --forestto see the parent process. This can help you track down what startedpsysh. - Check Supervisor/PM2/Other Managers:
Review your process manager configs to ensure you’re not accidentally running Tinker. - Check for Web Tinker Packages:
If you have a web-based Tinker package installed, ensure no one is using it or leaving sessions open.
Stopping the Process
If you determine the process is not needed, you can safely kill it:
kill <pid>
Replace <pid> with the process ID of the psysh process.
Summary:
Laravel only invokes psysh when you run Tinker. If you see it running otherwise, it’s likely due to an abandoned session, misconfiguration, or a web-based Tinker package. Investigate the process origin and stop it if unnecessary.