Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Laravel Octane appears to be restarted twice #72

Open
spawnia opened this issue Sep 8, 2021 · 8 comments
Open

Laravel Octane appears to be restarted twice #72

spawnia opened this issue Sep 8, 2021 · 8 comments

Comments

@spawnia
Copy link

spawnia commented Sep 8, 2021

Hi, thanks for this project 👋

I am trying to use this project as a lightweight alternative to chokidar for restarting Laravel Octane: https://laravel.com/docs/8.x/octane#watching-for-file-changes

When updating a watched file, it appears the process is restarted twice:

www-data@nemo-api:~$ vendor/bin/php-watcher artisan --arguments=octane:start --watch=app

[PHP-Watcher] 0.5.2
[PHP-Watcher] watching: app
[PHP-Watcher] starting `php artisan octane:start`
⠛
   INFO  Server running…

  Local: http://127.0.0.1:8000

  Press Ctrl+C to stop the server


[PHP-Watcher] restarting due to changes...
[PHP-Watcher] starting `php artisan octane:start`
[PHP-Watcher] starting `php artisan octane:start`

In Process.php line 170:
                              
  Process is already running  
                              

watch [-w|--watch [WATCH]] [-e|--ext [EXT]] [-i|--ignore [IGNORE]] [--exec [EXEC]] [--delay [DELAY]] [--signal [SIGNAL]] [--arguments [ARGUMENTS]] [--config [CONFIG]] [--no-spinner] [--] <script>

If you need to reproduce this locally, a plain Laravel install with Octane should do:

@fritz-gerneth
Copy link

Had this issue with our own code with graceful shut downs. I.e. the watcher does not wait for the app to shutdown. Fixed & re-released this with this commit.

Not sure about the maintenance status of this project so will keep it maintained in our fork until there is clearance.

@spawnia
Copy link
Author

spawnia commented Jan 24, 2022

@fritz-gerneth I would like to try your solution. It appears you changed the package name in your fork, but it is not available from packagist. How can I install it?

Also, perhaps you can try and post a PR to this project. There does not seem to be much activity, but that might just be because the project is somewhat finished - it is a simple utility after all, and apart from major new PHP versions and bug fixes, it should not need much maintenance.

@fritz-gerneth
Copy link

It is now posted to packagist. Either install from packagist or use the phar file (which we use over here). As there were more fixes than this single one it's not a single PR. Will split up & cherry pick if there is activity from the maintainer

@spawnia
Copy link
Author

spawnia commented Jan 24, 2022

Thank you @fritz-gerneth, installing with composer require --dev funct-gmbh/php-watcher worked.

Restarting now works, but it appears a bit imperfect - there is a message telling me the app crashed when I simply change whitespace in a file to trigger a reload:

root@59d2aec7e8b2:/var/www# vendor/bin/php-watcher artisan --arguments=octane:start --watch=app

[PHP-Watcher] 1.0.0
[PHP-Watcher] watching: app
[PHP-Watcher] starting `php artisan octane:start`
⠏
   INFO  Server running…

  Local: http://127.0.0.1:8000

  Press Ctrl+C to stop the server

[PHP-Watcher] app crashed - waiting for file changes before starting...

[PHP-Watcher] restarting due to changes...
[PHP-Watcher] starting `php artisan octane:start`
⡇
   INFO  Server running…

  Local: http://127.0.0.1:8000

  Press Ctrl+C to stop the server

@fritz-gerneth
Copy link

fritz-gerneth commented Jan 24, 2022

Weird stuff.. It doesn't do that for me but restarts with the proper message... That'd mean artisan would quit with a non-zero code. Could you check the exit code (echo $?) when starting the process manually & terminate it kill -INT $PID ?

( I also pushed v1.0.1 to include the code on app crash )

@spawnia
Copy link
Author

spawnia commented Jan 24, 2022

The process exits with code 137 after terminating it with kill -INT. The output of the updated version confirms that:

[PHP-Watcher] app crashed (137) - waiting for file changes before starting...

What exact command are you using to watch octane?

@fritz-gerneth
Copy link

Not using Laravel but for ReactPHP directly (i.e. php-watcher src/index.php) but in general this should work with every script/language).
Not knowing the intrinsics I do not know why artisan would return with a 137 code (which it apparently does even without the php-watcher infront). Might be a topic for the laravel community :)

@spawnia
Copy link
Author

spawnia commented Jun 28, 2022

It appears that Octane generally does not fail gracefully on SIGTERM, see laravel/octane#469

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants