Skip to content
This repository was archived by the owner on Oct 17, 2024. It is now read-only.

Configuration

scil edited this page Sep 26, 2019 · 35 revisions

Config

  1. Publish server config file
    php artisan vendor:publish --tag=fly-server .

  2. Edit server config file
    <project_root_dir>/fly.conf.php.

  3. Publish app config file
    php artisan vendor:publish --tag=fly-app .

  4. Edit app config file <project_root_dir>/config/laravelfly.php.
    Note: items prefixed with "/** depends " deverve your consideration.

  5. If you put some custome codes before $app in bootstrap\app.php, e.g. definding some const, please move them to a new file app-before.php at the same dir, then include this file in app.php and <project_root_dir>/fly.conf.php.

Two optional steps to allow you use same code for LaravelFly and PHP-FPM

  1. Edit <project_root_dir>/app/Http/Kernel.php, change class Kernel extends HttpKernel to
if (defined('LARAVELFLY_MODE')) { class WhichKernel extends \LaravelFly\MidKernel{} } else { class WhichKernel extends HttpKernel{} } class Kernel extends WhichKernel 
  1. If you use tinker(), put this line at the top of public/index.php :
    function tinker(){ return '';}

This line avoids error Call to undefined function tinker() when you use php-fpm with tinker() left in your code.

Optional Config

  • exclude folders from code inspection in PHPStorm:

    • vendor/scil/laravel-fly-files/offcial_files
    • vendor/scil/laravel-fly/tests/offcial_files
  • composer require --dev "shixinke/php-ide-helper" which is useful in IDE development. An alternative is eaglewu/swoole-ide-helper:dev-master .

  • Config and restart nginx: swoole http server lacks some http functions, so it's better to use swoole with other http servers like nginx. There is a nginx site conf example at vendor/scil/laravel-fly/config/nginx+swoole.conf.

  • Connection pool. For example:

'mysql' => [ 'driver' => 'mysql', 'pool'=>[ // a pool uses https://github.com/open-smf/connection-pool 'class' => 'LaravelFly\Map\Illuminate\Database\Pool\SmfPool', 'minActive' => 10, 'maxActive' => 30, 'maxWaitTime' => 5, 'maxIdleTime' => 20, 'idleCheckInterval' => 10, ], ... ], 'redis' => [ 'default' => [ 'pool'=>[], ] , ], 
  • MySql coroutine can be used. Ensure const LARAVELFLY_COROUTINE = true; in fly.conf.php, then add 'coroutine' => true, to config/database. This feature is still under dev.
'mysql' => [ 'driver' => 'mysql', 'coroutine' => true, ... ], 

Run jobs or listeners in swoole tasks

  1. edit `fly.conf.php'
'task_worker_num' => 10, // set a reasonable value 
  1. edit config/laravelfly.php (optional)
 'swoole-job' => [ 'delay' => 0, 'memory' => 128, 'timeout' => 60, 'tries' => 0, ], 
  1. for job: edit a job file

Event listener should `implements ShouldQueue.

 public function __construct() { $this->swoole = true; } 
  1. for event listener: edit App\Providers\EventServiceProvider
 protected $swooleListeners = [ 'App\Listeners\XxxListener', ]; 

Redis Driver supporting coroutine

  1. install swoole with compile option --enable-async-redis

  2. edit config/database.php

'redis' => [ 'client' => defined('LARAVELFLY_COROUTINE') && LARAVELFLY_COROUTINE && class_exists('Swoole\Coroutine\Redis') ? 'swoole-redis' : 'predis', 'default' => [ 'host' => env('REDIS_HOST', '127.0.0.1'), 'password' => env('REDIS_PASSWORD', null), 'port' => env('REDIS_PORT', 6379), 'database' => 0, 'var_serialize'=>false, // if serialize php var ], ], 

note:

  • not implemented methods: scan object sort migrate hscan sscan zscan
  • no support cluster
Clone this wiki locally