Debug Guideline

Although this package provides a sandbox container to prevent properties of container being influenced by your codes, sometimes there are still other unexpected issues. This guideline can shed some light on your debugging.

  • Make some changes in your config/swoole_http.php
  1. 'server' => [
  2. 'options' => [
  3. 'daemonize' => false,
  4. 'worker_num' => 1,
  5. ]
  6. ],
  7. 'ob_output' => false,

Limiting your worker number is to make sure your requests won't be processed by different workers. Turn off ob_output can help you dump some debug message on the console.

  • For example, if you get the same auth user in every request, you can try to dump some message in Illuminate\Auth\AuthServiceProvider::class
  1. protected function registerAuthenticator()
  2. {
  3. $this->app->singleton('auth', function ($app) {
  4. var_dump('auth resoved');
  5. // the reset code
  6. }
  7. }

Restart your server and inspect your console if your auth instance being resolved every time.

  • There are some pre-resolved instances that will be shared by sandbox container:
  1. 'view', 'files', 'session', 'session.store', 'routes',
  2. 'db', 'db.factory', 'cache', 'cache.store', 'config', 'cookies',
  3. 'encrypter', 'hash', 'router', 'translator', 'url', 'log'

These instances won't be resolved in every request. You can still set specific instances to instances config in swoole_http.php to reset them like below:

After v2.5.0, you can customize your pre-resolved list in pre_resolved in swoole_http.php config.

  1. /*
  2. |--------------------------------------------------------------------------
  3. | Instances here will be cleared on every request.
  4. |--------------------------------------------------------------------------
  5. */
  6. 'instances' => [
  7. 'log', 'cache'
  8. ],
  • Some providers might use dirty app to register their instances, for example, in PaginationServiceProvider:
  1. Paginator::currentPageResolver(function ($pageName = 'page') {
  2. $page = $this->app['request']->input($pageName);
  3. // ...
  4. });

The app variable is not injected from the closure. It's from the service provider itself. However, service providers are only registered in the very beginning of booting up application. So, the request instance here won't be refreshed. The better way should be:

  1. Paginator::currentPageResolver(function ($pageName = 'page') use ($app) {
  2. $page = $app['request']->input($pageName);
  3. // ...
  4. });

So this package provides a solution for this kind of situations. You can specify the service providers you want to re-register every time. Just add your service providers to providers config in swoole_http.php:

  1. /*
  2. |--------------------------------------------------------------------------
  3. | Providers here will be registered on every request.
  4. |--------------------------------------------------------------------------
  5. */
  6. 'providers' => [
  7. Illuminate\Pagination\PaginationServiceProvider::class,
  8. ],

The package will replace the app in service container with the sandbox app automatically.

  • If the packages you installed or any providers are related to authentication(eg. Laravel Passport), please reset them manually.

  • If you install other packages in your application, you should try to make a minimum implementation in a clean Laravel project first to see if the bug still happens. Some packages might have some dirty codes to cause unexpected bugs.