Skip to content
scil edited this page Jul 21, 2018 · 2 revisions

Start

Execute

php vendor/scil/laravel-fly/bin/fly start [$server_config_file]

Argument $server_config_file is optional, default is <project_root_dir>/fly.conf.php.

You can make multiple config files which have different listen_port, then you can run multiple server.

Note: LaravelFly will not supply an artisan command to run server, for the sake of less memory usage and the hot reload control (files loaded by artisan can't be hot reloaded).

Stop

php vendor/scil/laravel-fly/bin/fly stop [$server_config_file]

Another method is in php code file, making your own swoole http server by extending 'LaravelFly\Server\HttpServer' or creating a event handler, and use $this->server->shutdown(); .

Restart

php vendor/scil/laravel-fly/bin/fly restart [$server_config_file]

Debug

LaravelFlyServer runs in cli mode, so LaravelFly debug is to debug a script

php vendor/scil/laravel-fly/bin/fly <start|stop|restart>

To debug LaravelFly on a remote host such as vagrant, read Debugging remote CLI with phpstorm then use a command like this:

php -dxdebug.remote_host=192.168.1.2  vendor/scil/laravel-fly/bin/fly <start|stop|restart>

replace 192.168.1.2 with your ip where phpstorm is.

Note:

  • swoole 4.0 may not support xdebug totally.
  • composer update/require may slow when enable XDebug in CLI environment

Reload All Workers Gracefully: swoole server reloading

Swoole server has a main process, a manager process and one or more worker processes.If you set 'worker_num' => 4, there are 6 processes.The first the main process, the second is the manager process, and the last four are all worker processes.

Swoole server reloading has no matter with the main process or the manager process. Swoole server reloading is killing worker processes gracefully and start new.

Gracefully: worker willl finish its work before die.

Two methods to reload

  • Execute
php vendor/scil/laravel-fly/bin/fly reload [$server_config_file]
  • Edit fly.conf.php
'watch'=>[
    __DIR__.'/app',
    __DIR__.'/routes/web.php',
],

Hot Reload On Code Change

This feature is useless most times, because you can use php-fpm when devoleping.

By using swoole server reloading, it's possible to hot reload on code change, because any files required or included in 'WorkerStart' callback will be requied or included again when a new worker starts.

Note, files required or included before 'WorkerStart' will keep in memory, even swoole server reloads.

So it's better to include/require files which change rarely before 'WorkerStart' to save memory, to include/require files which change often in 'WorkerStart' callback to hot reload.

You could moniter some files and reload server(two methods above) , just make sure there files are required/included in 'WorkerStart' callback.