Giter VIP home page Giter VIP logo

Comments (7)

onanying avatar onanying commented on July 17, 2024

@peinhu 我这里 ab 压测没有复现出来,但是我觉得应该可以通过以下方式看能不能解决,把这两个 swoole 的默认值调更大一些

from mix.

onanying avatar onanying commented on July 17, 2024

@peinhu 已经确认是 swoole 的 bug swoole/swoole-src#3079 , swoole v4.4.16 已经修复该问题。

from mix.

peinhu avatar peinhu commented on July 17, 2024

我用的就是swoole v4.4.16,还是有这个问题

swoole

Swoole => enabled
Author => Swoole Team <[email protected]>
Version => 4.4.16
Built => Feb 19 2020 08:39:09
coroutine => enabled
trace_log => enabled
epoll => enabled
eventfd => enabled
signalfd => enabled
cpu_affinity => enabled
spinlock => enabled
rwlock => enabled
sockets => enabled
openssl => OpenSSL 1.0.1e-fips 11 Feb 2013
http2 => enabled
pcre => enabled
zlib => 1.2.3
mutex_timedlock => enabled
pthread_barrier => enabled
futex => enabled
mysqlnd => enabled
async_redis => enabled

Directive => Local Value => Master Value
swoole.enable_coroutine => On => On
swoole.enable_library => On => On
swoole.enable_preemptive_scheduler => Off => Off
swoole.display_errors => On => On
swoole.use_shortname => On => On
swoole.unixsock_buffer_size => 8388608 => 8388608

复现代码:

//mixphp 
//TestController.php
<?php

namespace App\Http\Controllers;

use App\Http\Helpers\ResponseHelper;
use Mix\Http\Message\ServerRequest;
use Mix\Http\Message\Response;

class TestController
{
    public function uploadData(ServerRequest $request, Response $response)
    { 
        $data = $request->getAttribute('data');
        $healthData = json_decode($data)->health_data;

        $content = ['code' => 0, 'message' => 'OK'];

        return ResponseHelper::json($response, $content);
    }

}
<?php
//mixphp 
//route.php
return [

    // 路由
    [
        // 名称
        'name'       => 'route',
        // 类路径
        'class'      => \Mix\Route\Router::class,
        // 初始方法
        'initMethod' => 'parse',
        // 属性注入
        'properties' => [
            // 默认变量规则
            'defaultPattern' => '[\w-]+',
            // 路由变量规则
            'patterns'       => [
                'id' => '\d+',
            ],
            // 全局中间件
            'middleware'     => [\App\Http\Middleware\GlobalMiddleware::class],
            // 路由规则
            'rules'          => [
 
                '/api'               => [
                    // 分组中间件
                    'middleware' => [\App\Http\Middleware\GroupMiddleware::class],
                    // 分组路由规则
                    'rules'      => [
                        'POST /test/upload_data' => [[\App\Http\Controllers\TestController::class, 'uploadData']],
                    ],
                ],
            ],
        ],
    ],

];

//data参数,post提交 {"health_data":[{"mac":"e0e4473f7311","aaaa":"36.7","bbbb":"0","cccccc":"8","dddddd":"0"},{"mac":"f52b02f12122","aaaa":"36.7","bbbb":"0","cccccc":"0","dddddd":"0"},{"mac":"f52b02f121aa","aaaa":"36.7","bbbb":"0","cccccc":"0","dddddd":"0"},{"mac":"f52b02f121bb","aaaa":"36.7","bbbb":"0","cccccc":"0","dddddd":"0"},{"mac":"f52b02f121cc","aaaa":"36.7","bbbb":"0","cccccc":"0","dddddd":"0"},{"mac":"f52b02f121dd","aaaa":"36.7","bbbb":"0","cccccc":"0","dddddd":"0"},{"mac":"f52b02f121ee","aaaa":"36.7","bbbb":"0","cccccc":"0","dddddd":"0"},{"mac":"f52b02f121ff","aaaa":"36.7","bbbb":"0","cccccc":"0","dddddd":"0"},{"mac":"f52b02f121gg","aaaa":"36.7","bbbb":"0","cccccc":"0","dddddd":"0"},{"mac":"f52b02f121hh","aaaa":"36.7","bbbb":"0","cccccc":"0","dddddd":"0"},{"mac":"f52b02f121ii","aaaa":"36.7","bbbb":"0","cccccc":"0","dddddd":"0"},{"mac":"f52b02f121jj","aaaa":"36.7","bbbb":"0","cccccc":"0","dddddd":"0"},{"mac":"f52b02f121kk","aaaa":"36.7","bbbb":"0","cccccc":"0","dddddd":"0"},{"mac":"f52b02f121ll","aaaa":"36.7","bbbb":"0","cccccc":"0","dddddd":"0"},{"mac":"f52b02f121mm","aaaa":"36.7","bbbb":"0","cccccc":"0","dddddd":"0"},{"mac":"f52b02f121nn","aaaa":"36.7","bbbb":"0","cccccc":"0","dddddd":"0"}]}

from mix.

peinhu avatar peinhu commented on July 17, 2024

多提交几次就会出现,我是一般第三次提交会出现,也有可能第二次出现。

from mix.

onanying avatar onanying commented on July 17, 2024

这个bug 和框架无关的,我现在这里压测 4.4.16 已经无法复现,你可以用原生代码试试,用 ab 压测:

<?php

function run($func)
{
    $scheduler = new \Swoole\Coroutine\Scheduler;
    $scheduler->set([
        'hook_flags' => SWOOLE_HOOK_ALL,
    ]);
    $scheduler->add(function () use ($func) {
        call_user_func($func);
    });
    $scheduler->start();
}

run(function(){

	$server = new \Swoole\Coroutine\Http\Server("0.0.0.0", 9502, false);
    $server->handle('/', function ($request, $response) {

    	var_dump(strlen($request->rawContent()));

        $response->end("<h1>Index</h1>");
    });
    $server->start();

});

from mix.

onanying avatar onanying commented on July 17, 2024

@peinhu 我在 linux 用原生和框架都 ab 压测没有复现,这个问题不在处理

System         Name:      linux
PHP            Version:   7.2.12
Swoole         Version:   4.4.16
Framework      Version:   2.1.15

from mix.

onanying avatar onanying commented on July 17, 2024

@peinhu 新的版本中 json 会被自动解析,也就是说你的第二行那里会抛出异常,因为已经转换 https://github.com/mix-php/mix/blob/master/src/http-message/src/Factory/ServerRequestFactory.php#L109

$data = $request->getAttribute('data');
$healthData = json_decode($data)->health_data;

from mix.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.