-
Notifications
You must be signed in to change notification settings - Fork 41
Coding Requirement
Global vars are only global in single swoole worker.It's better not to use super global vars like $_GET, $_POST.
Swoole workers run in different process, vars are not shared by different workers.
Methods to share vars between workers:
- Swoole tools like Table, Channel, ...
- Yac, Redis, Memcached, ...
name | replacement |
---|---|
header | Laravel Api: $response->header |
setcookie | Laravel Api: $response->cookie |
-
php configuration should keep same in any requests. Any changes of php configuration must be made before any requests (that is, made on worker ).
-
constants should keep same in all requests.
-
static props should keep consistent.
-
Illuminate\Pagination\Paginator: currentPathResolver,currentPageResolver,viewFactoryResolver,defaultView,defaultSimpleView .
-
Illuminate\Database\Eloquent\Model: globalScopes ( Global Scopes ) is an associated array, its values on the same key should always be same. For example, follwing code should not coexist in a project, because global scope 'age' means different closure.They should be merged into single closure.
static::addGlobalScope('age', function (Builder $builder) { $builder->where('age', '>', 200); }); static::addGlobalScope('age', function (Builder $builder) { $builder->where('age', '>', 200000000000000000000000000); }); // The two addGlobalScope above should be merged into one, like this: static::addGlobalScope('age', function (Builder $builder) { if(Request::has('age')) $builder->where('age', '>', 200); else $builder->where('age', '>', 200000000000000000000000000); });
- In Mode Map, If you use Laravel Macros, an object's Macros with same name should always be same if the object is made on worker, like addGlobalScope.
-
Mode Map uses coroutine, so different requests can be handled by server concurrently. Suppose the server is handling a request, meet co::sleep(3)
, then it goes to handle another request, later go back to the first request.
- Coroutine can not be used with route definition in route files, as there is no coroutine refactor for 'groupStack' in fly\Router.php.
Route::get('/', 'Controller@home'); // this line is not valid, as it will be executed by Router.php which has no coroutine support for groupStack co::sleep(100); Route::get('/test', function () { co::sleep(100); // this line is valid. });