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
plugin是個目錄,沒法直接include吧
升級后又是新的報錯
#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...')
說明一下:config/plugin/webman/console/app.php
文件的exclude_pattern
配置項是為了讓打包出來的文件相對小一些,去掉一些不需要的目錄,比如Test
目錄,這是一個正則表達式,如果打包出來的phar
文件有問題,請自己修改對應(yīng)的正則即可,因為每個人用到的依賴庫不一樣,如果不怕打包的phar
文件太大,完全可以把exclude_pattern
設(shè)置為null
。
另外附上一張,剛才測試的結(jié)果圖。
vendor肯定要打包進去的,exclude_pattern的存在可以忽略那些測試文件和文檔目錄,只打包進去項目必要的文件,你可以把它改成null,甚至可以exclude_files配置項目設(shè)置為空數(shù)組,再次進行打包
exclude_pattern設(shè)置為null,即是不忽略整個項目的所有文件和目錄,exclude_files置空表示不忽略單個文件。
也就是說exclude_pattern為null和exclude_files為空數(shù)組的時候,打包整個webman項目
新下載的框架可以用
之前的就不可以用
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
可以發(fā)一下config/plugin/webman/console/app.php文件的配置,包括你項目所需要的依賴庫,我安裝測試一下。
如果可以的話,發(fā)一下打包后的phar文件,我解包出來看看少了哪些文件
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'
]
];
composer.json
{
"name": "workerman/webman",
"type": "project",
"keywords": [
"high performance",
"http service"
],
"homepage": "http://www.wtbis.cn",
"license": "MIT",
"description": "High performance HTTP Service Framework.",
"authors": [
{
"name": "walkor",
"email": "walkor@workerman.net",
"homepage": "http://www.wtbis.cn",
"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"
}
}
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 我直接復(fù)制你的composer.json
文件的依賴包,然后執(zhí)行composer update
,
其他配置不變,然后打包運行,都是正常的
另外補充一點,phar
文件不允許動態(tài)修改里面的內(nèi)容,如果需要上傳文件或者需要生成臨時文件,可以參考rumtime_path
函數(shù),在當前目錄下生成臨時目錄。
命令行還是和webman/console
包的webman一樣使用,
因為打包后的phar
文件的入口文件其實就是webman/console
包的webman
文件。
mv build/webman.phar build/webman
chmod +x build/webman
build/webman version
@Tinywan 你把 webman/console 的配置 修改成
'exclude_pattern' => null,
'exclude_files' => [],
就好了
@Tinywan
composer create-project workerman/webman mywebman
cd mywebman && rm composer.lock -f
// composer.json完全修改成你發(fā)的
vim composer.json
composer install
php webman phar:pack
php build/webman.phar start
結(jié)果也是一樣可以的
你所說的配置信息不全,是因為我忽略掉了dev
環(huán)境的包,還有就是webman/console
已經(jīng)包含了symfony/console
,所以我就刪除了composer.json文件里面的symfony/console
感謝 @fuzqing @yzh52521 。是我本地Docker環(huán)境打包的不行,在測試環(huán)境試了一把是可以的,本地Docker打包為啥不行的問題我在找一下問題