Watch Star Fork

hhxsv5 / laravel-sPHPMIT

与超过 300 万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
一键复制 编辑 原始数据 按行查看 历史 5.34 KB XieBiao 提交于 2018-08-21 21:42 . fix $_SERVER

Known issues

Use package jenssegers/agent

Listen System Event

// Reset Agent
\Event::listen('laravels.received_request', function (\Illuminate\Http\Request $req, $app) {

Use package barryvdh/laravel-debugbar

Not support cli mode officially, you need to remove the logic of runningInConsole, but there may be some other issues.

// Search runningInConsole(), then annotate it
$this->enabled = $configEnabled /*&& !$this->app->runningInConsole()*/ && !$this->app->environment('testing');

Use package overtrue/wechat

The asynchronous notification callback will be failing, because $app['request'] is empty, give it a value.

public function notify(Request $request)
    $app = $this->getPayment();//Get payment instance
    $app['request'] = $request;//Add this line to the original code and assign the current request instance to $app['request']
    $response = $app->handlePaidNotify(function ($message, $fail) use($id) {
    return $response;

Use package laracasts/flash

Flash messages are held in memory all the time. Appending to $messages when call flash() every time, leads to the multiple messages. There are two solutions.

1.Reset $messages by middleware app('flash')->clear();.

2.Re-register FlashServiceProvider after handling request, Refer register_providers.

Singleton controller

1.Incorrect usage.

namespace App\Http\Controllers;
class TestController extends Controller
    protected $userId;
    public function __construct()
        // Incorrect usage: TestController is singleton instance, subsequent requests will misread the userId generated by the first request.
        $this->userId = session('userId');
    public function testAction()
        // read $this->userId;

2.Correct usage.

namespace App\Http\Controllers;
class TestController extends Controller
    protected function getUserId()
        return session('userId');
    public function testAction()
        // call $this->getUserId() to get $userId

Cannot call these functions

  • flush/ob_flush/ob_end_flush/ob_implicit_flush: swoole_http_response does not support flush.

  • dd()/exit()/die(): will lead to Worker/Task/Process quit right now, suggest jump out function call stack by throwing exception.

  • header()/setcookie()/http_response_code(): Make HTTP response by Laravel/Lumen Response only in LaravelS underlying.

Cannot use these global variables


Size restriction

  • The max size of GET request's header is 8KB, restricted by Swoole, the big Cookie will lead to parse Cookie fail.

  • The max size of POST data/file is restricted by Swoole package_max_length, default 2M.

Inotify reached the watchers limit

Warning: inotify_add_watch(): The user limit on the total number of inotify watches was reached

  • Inotify limit is default 8192 for most Linux, but the amount of actual project may be more than it, then lead to watch fail.

  • Increase the amount of inotify watchers to 524288: echo fs.inotify.max_user_watches=524288 | sudo tee -a /etc/sysctl.conf && sudo sysctl -p, note: you need to enable privileged for Docker.


See Laruence's blog Do NOT USE (include/require)_once

  • To include the files about class/interface/trait/function, sugguest to use (include/require)_once. In other cases, use include/require.

  • In the multi-process mode, the child process inherits the parent process resource. Once the parent process includes a file that needs to be executed, the child process will directly return true when it uses require_once(), causing the file to fail to execute. Now, you need to use include/require.

If Swoole < 1.9.17

After enabling handle_static, static resource files will be handled by LaravelS. Due to the PHP environment, MimeTypeGuesser may not correctly recognize MimeType. For example, Javascript and CSS files will be recognized as text/plain.


1.Upgrade Swoole to 1.9.17+.

2.Register a custom MIME guesser.

// MyGuessMimeType.php
use Symfony\Component\HttpFoundation\File\MimeType\MimeTypeGuesserInterface;
class MyGuessMimeType implements MimeTypeGuesserInterface
    protected static $map = [
        'js'  => 'application/javascript',
        'css' => 'text/css',
    public function guess($path)
        $ext = pathinfo($path, PATHINFO_EXTENSION);
        if (strlen($ext) > 0) {
            return Arr::get(self::$map, $ext);
        } else {
            return null;
// AppServiceProvider.php
use Symfony\Component\HttpFoundation\File\MimeType\MimeTypeGuesser;
public function boot()
    MimeTypeGuesser::getInstance()->register(new MyGuessMimeType());

评论 ( 0 )