-
Notifications
You must be signed in to change notification settings - Fork 41
Data Pollution
Objects which created before request may be changed during a request, and the changes maybe not right for subsequent requests.For example, a event registered in a request will persist in subsequent requests. Second example, app('view')
has a protected property "shared", which sometime is not appropriate to share this property across different requests.
Global variables and static members have similar problems.
Mode Map is more complicated than Mode Backup. Requests are not handled one by one.
There are three solutions.
The first is to backup some objects before any request, and restore them after each request .\LaravelFly\Application
extends \Illuminate\Foundation\Application
, use method "backUpOnWorker" to backup, and use method "restoreAfterRequest" to restore.This method is call Mode Backup. Mode Backup only handle laravel's key objects, such as app, event.
This solution can not use swoole's coroutine.
The second is to clone or create new objects such as app/event/.. for each request.
This is what [laravel-swoole] does.
The third is to refactor laravel's services, moving related members to a new associative array with coroutine id as keys. This method is called Mode Map.
Mode Backup uses Sollution 1.
Mode Map uses Sollution 3 plus a little Sollution 2 ( by default, only objects app['url'] and app['routes'] are cloned because they are rarely referenced by your code)
- Start
- Coding Guideline
- Deploy and OS Configuration
- New API
- Design
- Dev about Mode Map
- Dev about Mode Backup