Skip to content
scil edited this page Aug 30, 2018 · 4 revisions

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.

Solution 1st

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.

Solution 2nd

The second is to clone or create new objects such as app/event/.. for each request.

This is what [laravel-swoole] does.

Solution 3rd

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.

LaravelFly's choice

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)