scil / LaravelFly

To be an absolutely safe solution to speed up Laravel with Swoole. Preloading + Coroutine and Tinker Online.
457 stars 41 forks source link

修改建议 #27

Closed zhenyangze closed 6 years ago

zhenyangze commented 6 years ago

wiki说明修改

https://github.com/scil/LaravelFly/wiki/Configuration 修改

class WhichKernel extends \LaravelFly\MidKernel{}

class WhichKernel extends \LaravelFly\Kernel{}

代码修改

src/LaravelFly/Map/Util/Dict.php中,修改if (static::$normalAttriForObj ?? false) {if (isset(static::$normalAttriForObj)) {

类似的还有static::$arrayAttriForObj, static::$arrayStaticAttri

scil commented 6 years ago

MidKernel is required.

why isset(static::$normalAttriForObj) ?

wi1dcard commented 6 years ago

Hi @zhenyangze , I think you get confused with ?? and ?:.

See http://php.net/manual/en/migration70.new-features.php#migration70.new-features.null-coalesce-op

zhenyangze commented 6 years ago
➜  laravel56 git:(yangze_laravels_speed) ✗ php vendor/scil/laravel-fly/bin/fly start
[INFO] conf: /Users/yangze/Documents/work/git/laravel56/fly.conf.php
[INFO] include pre-files
PHP Fatal error:  Class 'LaravelFly\MidKernel' not found in /Users/yangze/Documents/work/git/laravel56/app/Http/Kernel.php on line 7

Fatal error: Class 'LaravelFly\MidKernel' not found in /Users/yangze/Documents/work/git/laravel56/app/Http/Kernel.php on line 7

   Whoops\Exception\ErrorException  : Class 'LaravelFly\MidKernel' not found

  at /Users/yangze/Documents/work/git/laravel56/app/Http/Kernel.php: 7
     3| namespace App\Http;
     4|
     5| use Illuminate\Foundation\Http\Kernel as HttpKernel;
     6| if (defined('LARAVELFLY_MODE')) {
  >  7|     class WhichKernel extends \LaravelFly\MidKernel{}
     8| } else {
     9|     class WhichKernel extends HttpKernel{}
    10| }
    11|
zhenyangze commented 6 years ago
➜  laravel56 git:(yangze_laravels_speed) ✗ php vendor/scil/laravel-fly/bin/fly start
[INFO] conf: /Users/yangze/Documents/work/git/laravel56/fly.conf.php
[INFO] include pre-files
[FLY ERROR] bootstrap: Access to undeclared static property: LaravelFly\Map\Illuminate\View\Factory::$normalStaticAttri
[FLY ERROR] bootstrap: Access to undeclared static property: LaravelFly\Map\Illuminate\View\Factory::$normalStaticAttri
[FLY ERROR] bootstrap: Access to undeclared static property: LaravelFly\Map\Illuminate\View\Factory::$normalStaticAttri

Server ready for accepting requests!
[FLY ERROR] bootstrap: Access to undeclared static property: LaravelFly\Map\Illuminate\View\Factory::$normalStaticAttri
zhenyangze commented 6 years ago

this is my env:

➜  laravel56 git:(yangze_laravels_speed) ✗ php -v
PHP 7.1.3 (cli) (built: Nov  7 2017 02:26:44) ( NTS )
Copyright (c) 1997-2017 The PHP Group
Zend Engine v3.1.0, Copyright (c) 1998-2017 Zend Technologies
    with Zend OPcache v7.1.3, Copyright (c) 1999-2017, by Zend Technologies
    "require": {
        "php": ">=7.1.3",
        "fideloper/proxy": "~4.0",
        "laravel/framework": "5.6.*",
        "laravel/tinker": "~1.0",
        "scil/laravel-fly": "dev-master"
    },
scil commented 6 years ago

check file vendor\scil\laravel-fly\src\LaravelFly\Server\Common.php

    protected function parseOptions(array &$options)
    {
        static::includeFlyFiles($options);

        include_once __DIR__.'/../../MidKernel.php';   // MidKernel is here

        // as earlier as possible
        if ($options['pre_include'])
            $this->preInclude();                     //  this output: [INFO] include pre-files

you got '[INFO] include pre-files' , but why no MidKernel?

zhenyangze commented 6 years ago

parseOptions method

    protected function parseOptions(array &$options)
    {
        static::includeFlyFiles($options);

        // as earlier as possible
        if ($options['pre_include'])
            $this->preInclude();

        if (isset($options['pid_file'])) {
            $options['pid_file'] .= '-' . $options['listen_port'];
        } else {
            $options['pid_file'] = $this->root . '/bootstrap/laravel-fly-' . $options['listen_port'] . '.pid';
        }

        $appClass = '\LaravelFly\\' . $options['mode'] . '\Application';

        if (class_exists($appClass)) {
            $this->appClass = $appClass;
        } else {
            $this->echo("Mode in config file not valid, no appClass $appClass\n", 'WARN', true);
        }

        $kernelClass = $options['kernel'] ?? 'App\Http\Kernel';
        if (!(
            (LARAVELFLY_MODE === 'Backup' && is_subclass_of($kernelClass, \LaravelFly\Backup\Kernel::class)) ||
            (LARAVELFLY_MODE === 'Map' && is_subclass_of($kernelClass, \LaravelFly\Map\Kernel::class))
        )) {

            $kernelClass = \LaravelFly\Kernel::class;
            $this->echo(
                "LaravelFly default kernel used: $kernelClass, 
      please edit App/Http/Kernel like https://github.com/scil/LaravelFly/blob/master/doc/config.md",
                'WARN', true
            );
        }

includeFlyFiles method

    static function includeFlyFiles(&$options)
    {
        // all fly files are for Mode Map, except Config/SimpleRepository.php for Mode Backup
        if (empty(LARAVELFLY_SERVICES['config']))
            include_once __DIR__ . '/../../fly/Config/' . (LARAVELFLY_MODE === 'Map' ? '' : 'Backup') . 'Repository.php';

        static $mapLoaded = false;
        static $logLoaded = false;

        if ($options['mode'] === 'Map' && !$mapLoaded) {

            $mapLoaded = true;

            if (empty(LARAVELFLY_SERVICES['kernel']))
                include_once __DIR__ . '/../../fly/Http/Kernel.php';

            foreach (static::mapFlyFiles as $f => $offical) {
                require __DIR__ . "/../../fly/" . $f;
            }

        }
scil commented 6 years ago

I think that you are using an old version.

zhenyangze commented 6 years ago

Hi @zhenyangze , I think you get confused with ?? and ?:.

See http://php.net/manual/en/migration70.new-features.php#migration70.new-features.null-coalesce-op

sorry, write wrong, changed.

if (isset(static::$normalAttriForObj))

this is error report:

[FLY ERROR] bootstrap: Access to undeclared static property: LaravelFly\Map\Illuminate\View\Factory::$normalStaticAttri
zhenyangze commented 6 years ago

I think that you are using an old version.

maybe, i will update it.

zhenyangze commented 6 years ago

update version

i update all version, now is new version.

    protected function parseOptions(array &$options)
    {
        static::includeFlyFiles($options);

        include_once __DIR__.'/../../MidKernel.php';

then start laravelFly

first error

[INFO] conf: /Users/yangze/Documents/work/git/laravel56/fly.conf.php
PHP Notice:  Use of undefined constant LARAVELFLY_COROUTINE - assumed 'LARAVELFLY_COROUTINE' in /Users/yangze/Documents/work/git/laravel56/vendor/scil/laravel-fly/src/functions.php on line 24

Notice: Use of undefined constant LARAVELFLY_COROUTINE - assumed 'LARAVELFLY_COROUTINE' in /Users/yangze/Documents/work/git/laravel56/vendor/scil/laravel-fly/src/functions.php on line 24
PHP Notice:  Use of undefined constant LARAVELFLY_COROUTINE - assumed 'LARAVELFLY_COROUTINE' in /Users/yangze/Documents/work/git/laravel56/vendor/scil/laravel-fly/src/functions.php on line 41

Notice: Use of undefined constant LARAVELFLY_COROUTINE - assumed 'LARAVELFLY_COROUTINE' in /Users/yangze/Documents/work/git/laravel56/vendor/scil/laravel-fly/src/functions.php on line 41

second error

#0 /Users/yangze/Documents/work/git/laravel56/vendor/scil/laravel-fly/src/LaravelFly/Map/Illuminate/View/Factory.php(45): LaravelFly\Map\Illuminate\View\Factory::initStaticForCorontine(-1, true)
#1 /Users/yangze/Documents/work/git/laravel56/vendor/scil/laravel-fly/src/LaravelFly/Map/Illuminate/View/ViewServiceProvider.php(33): LaravelFly\Map\Illuminate\View\Factory->__construct(Object(Illuminate\View\Engines\EngineResolver), Object(Illuminate\View\FileViewFinder), Object(LaravelFly\Map\IlluminateBase\Dispatcher))
#2 /Users/yangze/Documents/work/git/laravel56/vendor/laravel/framework/src/Illuminate/View/ViewServiceProvider.php(43): LaravelFly\Map\Illuminate\View\ViewServiceProvider->createFactory(Object(Illuminate\View\Engines\EngineResolver), Object(Illuminate\View\FileViewFinder), Object(LaravelFly\Map\IlluminateBase\Dispatcher))
#3 /Users/yangze/Documents/work/git/laravel56/vendor/scil/laravel-fly-files/src/Container.php(696): Illuminate\View\ViewServiceProvider->Illuminate\View\{closure}(Object(LaravelFly\Map\Application), Array)

...
#27 /Users/yangze/Documents/work/git/laravel56/vendor/scil/laravel-fly/bin/fly(84): LaravelFly\Server\HttpServer->start()
#28 {main}[FLY ERROR] bootstrap: Access to undeclared static property: LaravelFly\Map\Illuminate\View\Factory::$normalStaticAttri
scil commented 6 years ago

there must be old codes!

publish new config files?

zhenyangze commented 6 years ago

i know first error sulution:

const LARAVELFLY_COROUTINE = true;

but second error need fixed

scil commented 6 years ago

config file:

        Illuminate\View\ViewServiceProvider::class => [
            '_replaced_by' => \LaravelFly\Map\Illuminate\View\ViewServiceProvider::class,
            'view', 'view.engine.resolver', 'blade.compiler'
        ],

and ensures vendor\scil\laravel-fly\src\LaravelFly\Map\Illuminate\View\Factory.php is included.

zhenyangze commented 6 years ago

do as you say, invalid.

scil commented 6 years ago

this line ?

        if (static::$normalStaticAttri ?? false) {

\vendor\scil\laravel-fly\src\LaravelFly\Map\Util\StaticDict.php

zhenyangze commented 6 years ago
[FLY ERROR] bootstrap: Access to undeclared static property: LaravelFly\Map\Illuminate\View\Factory::$normalStaticAttri
[FLY ERROR] bootstrap: Access to undeclared static property: LaravelFly\Map\Illuminate\Session\StartSession::$arrayAttriForObj