php webman.phar start 异常 Uncaught ErrorException: include(build/webman.phar/config/plugin): failed to open stream: phar error: "config/plugin" is not a file in phar

Tinywan
isSuperAdmin(r.sub)PHP Fatal error:  Uncaught ErrorException: include(phar:///var/www》tinywan.cn/build/webman.phar/config/plugin): failed to open stream: phar error: "config/plugin" is not a file in phar "/var/www/micro.webman.tinywan.cn/build/webman.phar" in phar:///var/www/tinywan.tinywan.cn/build/webman.phar/vendor/workerman/webman-framework/src/Config.php:113
1507 3 0
3个回答

nitron

plugin是个目录,没法直接include吧

  • Tinywan 2022-02-25

    目前遇到的问题就是插件的使用phar打包,但是没法使用

  • nitron 2022-02-25

    webman更新到1.2.4看看,我刚刚看了1.2.4Config做了点修改,针对phar的

  • yzh52521 2022-02-25

    上次试了一下打包 运行不了,一堆报错

  • walkor 2022-02-25

    这个问题修复过,更新到 webman-framework v1.2.4 或者后续更高版本试下

  • Tinywan 2022-02-25

    升级后又是新的报错

    #23 /var/www/micro.webman.tinywan.cn/build/webman.phar(5): require('phar:///var/www...')
    #24 {main}
    Error: Class 'Monolog\Handler\AbstractProcessingHandler' not found in phar:///var/www/micro.webman.tinywan.cn/build/webman.phar/vendor/monolog/monolog/src/Monolog/Handler/StreamHandler.php:26
    Stack trace:
    #0 phar:///var/www/micro.webman.tinywan.cn/build/webman.phar/vendor/composer/ClassLoader.php(571): include()
    #1 phar:///var/www/micro.webman.tinywan.cn/build/webman.phar/vendor/composer/ClassLoader.php(428): Composer\Autoload\includeFile('phar:///var/www...')
    #2 [internal function]: Composer\Autoload\ClassLoader->loadClass('Monolog\\Handler...')
    #3 phar:///var/www/micro.webman.tinywan.cn/build/webman.phar/vendor/monolog/monolog/src/Monolog/Handler/RotatingFileHandler.php(27): spl_autoload_call('Monolog\\Handler...')
    #4 phar:///var/www/micro.webman.tinywan.cn/build/webman.phar/vendor/composer/ClassLoader.php(571): include('phar:///var/www...')
    #5 phar:///var/www/micro.webman.tinywan.cn/build/webman.phar/vendor/composer/ClassLoader.php(428): Composer\Autoload\includeFile('phar:///var/www...')
    #6 [internal function]: Composer\Autoload\ClassLoader->loadClass('Monolog\\Handler...')
  • walkor 2022-02-25

    弄个新的webman项目,试下是否正常。我这没有发现这个问题。

  • nitron 2022-02-25

    vendor/monolog/monolog/src/Monolog/Handler/AbstractProcessingHandler.php 没打包进去?

  • Tinywan 2022-02-25

    不清楚,下午搞个新的试试

  • Tinywan 2022-02-25

    下载的新框架也是这样子

  • Tinywan 2022-02-25

    /var/www/webman # ./webman version
    Webman 1.2.4
    Webman-framework v1.2.4

北月

说明一下:config/plugin/webman/console/app.php文件的exclude_pattern配置项是为了让打包出来的文件相对小一些,去掉一些不需要的目录,比如Test目录,这是一个正则表达式,如果打包出来的phar文件有问题,请自己修改对应的正则即可,因为每个人用到的依赖库不一样,如果不怕打包的phar文件太大,完全可以把exclude_pattern设置为null
另外附上一张,刚才测试的结果图。

  • Tinywan 2022-02-25

    vendor不打包,项目能运行?

  • 北月 2022-02-25

    vendor肯定要打包进去的,exclude_pattern的存在可以忽略那些测试文件和文档目录,只打包进去项目必要的文件,你可以把它改成null,甚至可以exclude_files配置项目设置为空数组,再次进行打包

  • 北月 2022-02-25

    exclude_pattern设置为null,即是不忽略整个项目的所有文件和目录,exclude_files置空表示不忽略单个文件。
    也就是说exclude_pattern为null和exclude_files为空数组的时候,打包整个webman项目

  • yzh52521 2022-02-25

    新下载的框架可以用
    之前的就不可以用

    Stack trace:
    #0 phar:///Users/yuanzhihai/Sites/local/webman/build/webman.phar/vendor/php-di/php-di/src/Definition/Source/AnnotationBasedAutowiring.php(279): DI\Definition\Source\AnnotationBasedAutowiring->getAnnotationReader()
    #1 phar:///Users/yuanzhihai/Sites/local/webman/build/webman.phar/vendor/php-di/php-di/src/Definition/Source/AnnotationBasedAutowiring.php(68): DI\Definition\Source\AnnotationBasedAutowiring->readInjectableAnnotation(Object(ReflectionClass), Object(DI\Definition\ObjectDefinition))
    #2 phar:///Users/yuanzhihai/Sites/local/webman/build/webman.phar/vendor/php-di/php-di/src/Definition/Source/AnnotationBasedAutowiring.php(86): DI\Definition\Source\AnnotationBasedAutowiring->autowire('app\\middleware\\...')
    #3 phar:///Users/yuanzhihai/Sites/local/webman/build/webman.phar/vendor/php-di/php-di/src/Definition/Source/SourceChain.php(54): DI\Definition\Source\AnnotationBasedAutowiring->getDefinition('app\\middleware\\...')
    #4 phar:///Users/yuanzhihai/Sites/local/webman/build/webman.phar/vendor/php-di/php-di/src/Container.php(155): DI\Definition\Source\SourceChain->getDefinition('app\\middleware\\...')
    #5 phar:///Users/yuanzhihai/Sites/local/webman/build/webman.phar/vendor/php-di/php-di/src/Container.php(134): DI\Container->getDefinition('app\\middleware\\...')
    #6 phar:///Users/yuanzhihai/Sites/local/webman/build/webman.phar/vendor/workerman/webman-framework/src/Middleware.php(43): DI\Container->get('app\\middleware\\...')
    #7 phar:///Users/yuanzhihai/Sites/local/webman/build/webman.phar/support/bootstrap.php(60): Webman\Middleware::load(Array)
    #8 phar:///Users/yuanzhihai/Sites/local/webman/build/webman.phar/webman(6): require_once('phar:///Users/y...')
    #9 /Users/yuanzhihai/Sites/local/webman/build/webman.phar(5): require('phar:///Users/y...')
    #10 {main}
      thrown in phar:///Users/yuanzhihai/Sites/local/webman/build/webman.phar/vendor/php-di/php-di/src/Definition/Source/AnnotationBasedAutowiring.php on line 255
    
  • Tinywan 2022-02-25

    新下载的框架我这边测试不行,不知道怎么回事?

  • 北月 2022-02-25

    可以发一下config/plugin/webman/console/app.php文件的配置,包括你项目所需要的依赖库,我安装测试一下。
    如果可以的话,发一下打包后的phar文件,我解包出来看看少了哪些文件

  • Tinywan 2022-02-25

    app.php

    
    <?php
    return [
        'enable'            => true,
    
        'phar_file_output_dir'    => BASE_PATH . DIRECTORY_SEPARATOR . 'build',
    
        'phar_filename'     => 'webman.phar',
    
        'signature_algorithm'=> Phar::SHA256, //set the signature algorithm for a phar and apply it. The signature algorithm must be one of Phar::MD5, Phar::SHA1, Phar::SHA256, Phar::SHA512, or Phar::OPENSSL.
    
        'private_key_file'  => '', // The file path for certificate or OpenSSL private key file.
    
        'exclude_pattern'   => '#^(?!.*(config/plugin/webman/console/app.php|webman/console/src/Commands/(PharPackCommand.php|ReloadCommand.php)|LICENSE|composer.json|.github|.idea|doc|docs|.git|.setting|runtime|test|test_old|tests|Tests|vendor-bin|.md))(.*)$#',
    
        'exclude_files'     => [
            '.env', 'LICENSE', 'composer.json', 'composer.lock','start.php'
        ]
    ];
  • Tinywan 2022-02-25

    composer.json

    {
      "name": "workerman/webman",
      "type": "project",
      "keywords": [
        "high performance",
        "http service"
      ],
      "homepage": "http://www.workerman.net",
      "license": "MIT",
      "description": "High performance HTTP Service Framework.",
      "authors": [
        {
          "name": "walkor",
          "email": "walkor@workerman.net",
          "homepage": "http://www.workerman.net",
          "role": "Developer"
        }
      ],
      "support": {
        "email": "walkor@workerman.net",
        "issues": "https://github.com/walkor/webman/issues",
        "forum": "http://wenda.workerman.net/",
        "wiki": "http://workerman.net/doc/webman",
        "source": "https://github.com/walkor/webman"
      },
      "require": {
        "php": ">=7.4",
        "ext-json": "*",
        "ext-redis": "*",
        "ext-curl": "*",
        "ext-posix": "*",
        "ext-pcntl": "*",
        "workerman/webman-framework": "^1.2",
        "monolog/monolog": "^2.0",
        "ramsey/uuid": "^4.2",
        "alibabacloud/client": "^1.5",
        "aliyuncs/oss-sdk-php": "^2.4",
        "alibabacloud/sdk": "^1.8",
        "illuminate/redis": "^8.69",
        "symfony/cache": "^5.3",
        "phpoffice/phpspreadsheet": "^1.19",
        "workerman/gatewayclient": "^3.0",
        "symfony/console": "^5.4",
        "hashids/hashids": "^4.1",
        "openzipkin/zipkin": "^3.0",
        "zoujingli/ip2region": "^1.0",
        "workerman/crontab": "^1.0",
        "tinywan/webman-event": "^0.0.2",
        "tinywan/webman-validate": "^0.0.3",
        "topthink/think-orm": "^2.0",
        "webman/console": "^1.0",
        "godruoyi/php-snowflake": "^2.0",
        "smi2/phpclickhouse": "^1.4",
        "pusher/pusher-php-server": "^7.0",
        "tinywan/casbin": "^0.0.8",
        "webman/push": "^1.0",
        "tinywan/jwt": "^1.0"
      },
      "suggest": {
        "ext-event": "For better performance. "
      },
      "autoload": {
        "psr-4": {
          "" : "./"
        },
        "files": [
          "./support/helpers.php"
        ]
      },
      "require-dev": {
        "phpstan/phpstan": "^1.1",
        "friendsofphp/php-cs-fixer": "^3.2",
        "phpunit/phpunit": "^9.5",
        "kwn/php-rdkafka-stubs": "^0.0.1"
      },
      "repositories": {
        "packagist": {
          "type": "composer",
          "url": "https://mirrors.aliyun.com/composer//"
        }
      },
      "scripts": {
        "post-package-install": [
          "support\\Plugin::install"
        ],
        "pre-package-uninstall": [
          "support\\Plugin::uninstall"
        ],
        "test": "./vendor/bin/phpunit --bootstrap tests/bootstrap.php",
        "cs-fix": "./vendor/bin/php-cs-fixer fix",
        "php-stan": "./vendor/bin/phpstan analyse app"
      }
    }
    
  • yzh52521 2022-02-25
    return [
        'enable' => true,
    
        'phar_file_output_dir' => BASE_PATH . DIRECTORY_SEPARATOR . 'build',
    
        'phar_filename' => 'webman.phar',
    
        'signature_algorithm' => Phar::SHA256, //set the signature algorithm for a phar and apply it. The signature algorithm must be one of Phar::MD5, Phar::SHA1, Phar::SHA256, Phar::SHA512, or Phar::OPENSSL.
    
        'private_key_file' => '', // The file path for certificate or OpenSSL private key file.
    
        /*'exclude_pattern'   => '#^(?!.*(config/plugin/webman/console/app.php|webman/console/src/Commands/(PharPackCommand.php|ReloadCommand.php)|LICENSE|composer.json|.github|.idea|doc|docs|.git|.setting|runtime|test|test_old|tests|Tests|vendor-bin|.md))(.*)$#',
    
        'exclude_files'     => [
            '.env', 'LICENSE', 'composer.json', 'composer.lock','start.php'
        ]*/
        'exclude_pattern'  => null,
        'exclude_files'    => [],
    
    ];

    改成这样就都可以用了

北月

@Tinywan 我直接复制你的composer.json文件的依赖包,然后执行composer update,
其他配置不变,然后打包运行,都是正常的


另外补充一点,phar文件不允许动态修改里面的内容,如果需要上传文件或者需要生成临时文件,可以参考rumtime_path函数,在当前目录下生成临时目录。

  • yzh52521 2022-02-25

    @ fuzqing 打包后 怎么使用 命令行?

  • 北月 2022-02-25

    命令行还是和webman/console包的webman一样使用,
    因为打包后的phar文件的入口文件其实就是webman/console包的webman文件。
    mv build/webman.phar build/webman
    chmod +x build/webman
    build/webman version

  • yzh52521 2022-02-25

    @fuzqing 非常感谢! 完美了

  • Tinywan 2022-02-25

    你这明显composer.json配置信息不全,你看我发的

  • yzh52521 2022-02-25

    @Tinywan 你把 webman/console 的配置 修改成

    'exclude_pattern'  => null,
        'exclude_files'    => [],

    就好了

  • 北月 2022-02-25

    @Tinywan
    composer create-project workerman/webman mywebman
    cd mywebman && rm composer.lock -f
    // composer.json完全修改成你发的
    vim composer.json
    composer install
    php webman phar:pack
    php build/webman.phar start
    结果也是一样可以的
    你所说的配置信息不全,是因为我忽略掉了dev环境的包,还有就是webman/console已经包含了symfony/console,所以我就删除了composer.json文件里面的symfony/console

  • Tinywan 2022-02-26

    感谢 @fuzqing @yzh52521 。是我本地Docker环境打包的不行,在测试环境试了一把是可以的,本地Docker打包为啥不行的问题我在找一下问题

年代过于久远,无法发表回答
×
🔝