laravel octane 在请求中Artisan call会内存泄露, 求解

github提的issues被秒关
大神们试试 有没这情况

  • Octane Version: v1.0.15
  • Laravel Version: v8.64.0
  • PHP Version: 8.0.3
  • Server & Version: Swoole 4.6.6
  • Database Driver & Version: no

Description:

启动命令

php artisan octane:start --workers=1 --port=8000 --task-workers=4 --server=swoole --max-requests=0

路由 (route/api.php)

Route::get('/hello', function (Request $request) {
\Illuminate\Support\Facades\Artisan::call('hello');
return 'hello';
});

HelloCommand

<?php

namespace App\Console\Commands;

use Illuminate\Console\Command;

class HelloCommand extends Command
{
    /**
     * The name and signature of the console command.
     *
     * @var string
     */
    protected $signature = 'hello';

    /**
     * The console command description.
     *
     * @var string
     */
    protected $description = 'hello';

    /**
     * Create a new command instance.
     *
     * [[@return](https://learnku.com/users/31554)](https://learnku.com/users/31554) void
     */
    public function __construct()
    {
        parent::__construct();
    }

    /**
     * Execute the console command.
     *
     * [[@return](https://learnku.com/users/31554)](https://learnku.com/users/31554) int
     */
    public function handle()
    {
        $this->line('hello');
        logger('hello');
        return Command::SUCCESS;
    }
}

Steps To Reproduce:

 200    GET /api/hello ....................................................................................................................................................................................... 55.55 mb 7.16 ms
  200    GET /api/hello ....................................................................................................................................................................................... 55.68 mb 5.48 ms
  200    GET /api/hello ....................................................................................................................................................................................... 55.82 mb 4.76 ms
  200    GET /api/hello ....................................................................................................................................................................................... 55.95 mb 5.69 ms
  200    GET /api/hello ....................................................................................................................................................................................... 56.09 mb 4.64 ms
  200    GET /api/hello ....................................................................................................................................................................................... 56.22 mb 4.46 ms
  200    GET /api/hello ....................................................................................................................................................................................... 56.36 mb 4.74 ms
  200    GET /api/hello ....................................................................................................................................................................................... 56.49 mb 4.94 ms
  200    GET /api/hello ....................................................................................................................................................................................... 56.63 mb 4.57 ms
  200    GET /api/hello ....................................................................................................................................................................................... 56.76 mb 4.46 ms
  200    GET /api/hello ....................................................................................................................................................................................... 56.90 mb 5.04 ms
本作品采用《CC 协议》,转载必须注明作者和本文链接
《L01 基础入门》
我们将带你从零开发一个项目并部署到线上,本课程教授 Web 开发中专业、实用的技能,如 Git 工作流、Laravel Mix 前端工作流等。
《G01 Go 实战入门》
从零开始带你一步步开发一个 Go 博客项目,让你在最短的时间内学会使用 Go 进行编码。项目结构很大程度上参考了 Laravel。
讨论数量: 11

日志的文件资源吧,把日志去掉试试

再说这也看不出来内存泄漏

2年前 评论

@Imuyu 命令空执行也一样, 看代码貌似没处理octane 没专门为 Console Application类 做处理

2年前 评论

octane.php 暂时这样解决

'warm' => [
        ...Octane::defaultServicesToWarm(),
        ...[Illuminate\Contracts\Console\Kernel::class] //加这个解决每次需要初始化内存暴增的问题
    ],
2年前 评论

这是咋看出来内存泄露的?

2年前 评论
阿凡 (楼主) 2年前
Talentisan 8个月前

简单起了个demo,然后 ab -c 100 -n 10000 http://127.0.0.1:8000/hello/ 请求,观察了一下日志,大概在120m左右的时候,内存占用会重置到15M左右,不太确定是 php gc了还是 swoole gc了,又或者是octane。

2年前 评论
阿凡 (楼主) 2年前
minbaby (作者) 2年前
阿凡 (楼主) 2年前
minbaby (作者) 2年前

讨论应以学习和精进为目的。请勿发布不友善或者负能量的内容,与人为善,比聪明更重要!