打包后运行出现如上报错
配置文件 修改成以下:
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' => [], ];
修改之后报另个错误了。 TypeError: Return value of exception\Handler::render() must be an instance of Webman\Http\Response, instance of Workerman\Protocols\Http\Response returned in phar:///www/local.lis.com/build/webman.phar/exception/Handler.php:74 Stack trace: #0 phar:///www/local.lis.com/build/webman.phar/vendor/workerman/webman-framework/src/App.php(215): exception\Handler->render(Object(support\Request), Object(TypeError)) #1 phar:///www/local.lis.com/build/webman.phar/vendor/workerman/webman-framework/src/App.php(166): Webman\App::exceptionResponse(Object(TypeError), Object(support\Request)) #2 phar:///www/local.lis.com/build/webman.phar/vendor/workerman/workerman/Connection/TcpConnection.php(638): Webman\App->onMessage(Object(Workerman\Connection\TcpConnection), Object(support\Request)) #3 phar:///www/local.lis.com/build/webman.phar/vendor/workerman/workerman/Events/Select.php(295): Workerman\Connection\TcpConnection->baseRead(Resource id #538) #4 phar:///www/local.lis.com/build/webman.phar/vendor/workerman/workerman/Worker.php(2431): Workerman\Events\Select->loop() #5 phar:///www/local.lis.com/build/webman.phar/vendor/workerman/workerman/Worker.php(1555): Workerman\Worker->run() #6 phar:///www/local.lis.com/build/webman.phar/vendor/workerman/workerman/Worker.php(1397): Workerman\Worker::forkOneWorkerForLinux(Object(Workerman\Worker)) #7 phar:///www/local.lis.com/build/webman.phar/vendor/workerman/workerman/Worker.php(1371): Workerman\Worker::forkWorkersForLinux() #8 phar:///www/local.lis.com/build/webman.phar/vendor/workerman/workerman/Worker.php(549): Workerman\Worker::forkWorkers() #9 phar:///www/local.lis.com/build/webman.phar/vendor/webman/console/src/Application.php(109): Workerman\Worker::runAll() #10 phar:///www/local.lis.com/build/webman.phar/vendor/webman/console/src/Commands/StartCommand.php(28): Webman\Console\Application::run() #11 phar:///www/local.lis.com/build/webman.phar/vendor/symfony/console/Command/Command.php(298): Webman\Console\Commands\StartCommand->execute(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput)) #12 phar:///www/local.lis.com/build/webman.phar/vendor/symfony/console/Application.php(1015): Symfony\Component\Console\Command\Command->run(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput)) #13 phar:///www/local.lis.com/build/webman.phar/vendor/symfony/console/Application.php(299): Symfony\Component\Console\Application->doRunCommand(Object(Webman\Console\Commands\StartCommand), Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput)) #14 phar:///www/local.lis.com/build/webman.phar/vendor/symfony/console/Application.php(171): Symfony\Component\Console\Application->doRun(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput)) #15 phar:///www/local.lis.com/build/webman.phar/webman(30): Symfony\Component\Console\Application->run() #16 /www/local.lis.com/build/webman.phar(5): require('phar:///www/loc...') #17 {main}
报错说的很明确了,你的exception/Handler.php文件里exception\Handler::render()方法应该返回一个Webman\Http\Response对象,但是你返回了Workerman\Protocols\Http\Response。
exception/Handler.php
exception\Handler::render()
Webman\Http\Response
Workerman\Protocols\Http\Response
打包后的验证码不能用提示打不开字体我看了字体文件也是有的。权限也给了最高权限 phar:///www/local.lis.com/build/webman.phar/vendor/gregwar/captcha/src/Gregwar/Captcha/CaptchaBuilder.php 345 imagettfbbox(): Could not find/open font
[已解决]在验证码库里通过__DIR__读取的字体目录打包后要把字体文件移到build下修改__DIR__的读取方式 if ($font === null) { $realPath = \Phar::running() ? pathinfo(\Phar::running(false), PATHINFO_DIRNAME).'/Font':__DIR__.'/Font'; $font = $realPath . '/captcha'.$this->rand(0, 5).'.ttf'; }
配置文件 修改成以下:
修改之后报另个错误了。
TypeError: Return value of exception\Handler::render() must be an instance of Webman\Http\Response, instance of Workerman\Protocols\Http\Response returned in phar:///www/local.lis.com/build/webman.phar/exception/Handler.php:74 Stack trace: #0 phar:///www/local.lis.com/build/webman.phar/vendor/workerman/webman-framework/src/App.php(215): exception\Handler->render(Object(support\Request), Object(TypeError)) #1 phar:///www/local.lis.com/build/webman.phar/vendor/workerman/webman-framework/src/App.php(166): Webman\App::exceptionResponse(Object(TypeError), Object(support\Request)) #2 phar:///www/local.lis.com/build/webman.phar/vendor/workerman/workerman/Connection/TcpConnection.php(638): Webman\App->onMessage(Object(Workerman\Connection\TcpConnection), Object(support\Request)) #3 phar:///www/local.lis.com/build/webman.phar/vendor/workerman/workerman/Events/Select.php(295): Workerman\Connection\TcpConnection->baseRead(Resource id #538) #4 phar:///www/local.lis.com/build/webman.phar/vendor/workerman/workerman/Worker.php(2431): Workerman\Events\Select->loop() #5 phar:///www/local.lis.com/build/webman.phar/vendor/workerman/workerman/Worker.php(1555): Workerman\Worker->run() #6 phar:///www/local.lis.com/build/webman.phar/vendor/workerman/workerman/Worker.php(1397): Workerman\Worker::forkOneWorkerForLinux(Object(Workerman\Worker)) #7 phar:///www/local.lis.com/build/webman.phar/vendor/workerman/workerman/Worker.php(1371): Workerman\Worker::forkWorkersForLinux() #8 phar:///www/local.lis.com/build/webman.phar/vendor/workerman/workerman/Worker.php(549): Workerman\Worker::forkWorkers() #9 phar:///www/local.lis.com/build/webman.phar/vendor/webman/console/src/Application.php(109): Workerman\Worker::runAll() #10 phar:///www/local.lis.com/build/webman.phar/vendor/webman/console/src/Commands/StartCommand.php(28): Webman\Console\Application::run() #11 phar:///www/local.lis.com/build/webman.phar/vendor/symfony/console/Command/Command.php(298): Webman\Console\Commands\StartCommand->execute(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput)) #12 phar:///www/local.lis.com/build/webman.phar/vendor/symfony/console/Application.php(1015): Symfony\Component\Console\Command\Command->run(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput)) #13 phar:///www/local.lis.com/build/webman.phar/vendor/symfony/console/Application.php(299): Symfony\Component\Console\Application->doRunCommand(Object(Webman\Console\Commands\StartCommand), Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput)) #14 phar:///www/local.lis.com/build/webman.phar/vendor/symfony/console/Application.php(171): Symfony\Component\Console\Application->doRun(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput)) #15 phar:///www/local.lis.com/build/webman.phar/webman(30): Symfony\Component\Console\Application->run() #16 /www/local.lis.com/build/webman.phar(5): require('phar:///www/loc...') #17 {main}
报错说的很明确了,你的
exception/Handler.php
文件里exception\Handler::render()
方法应该返回一个Webman\Http\Response
对象,但是你返回了Workerman\Protocols\Http\Response
。打包后的验证码不能用提示打不开字体我看了字体文件也是有的。权限也给了最高权限
phar:///www/local.lis.com/build/webman.phar/vendor/gregwar/captcha/src/Gregwar/Captcha/CaptchaBuilder.php
345
imagettfbbox(): Could not find/open font
[已解决]在验证码库里通过__DIR__读取的字体目录打包后要把字体文件移到build下修改__DIR__的读取方式
if ($font === null) {
$realPath = \Phar::running() ? pathinfo(\Phar::running(false), PATHINFO_DIRNAME).'/Font':__DIR__.'/Font';
$font = $realPath . '/captcha'.$this->rand(0, 5).'.ttf';
}