Comments (7)
@peinhu 我这里 ab 压测没有复现出来,但是我觉得应该可以通过以下方式看能不能解决,把这两个 swoole 的默认值调更大一些
- https://www.kancloud.cn/onanying/mixphp2-1/1255336
- https://www.kancloud.cn/onanying/mixphp2-1/1367155
from mix.
@peinhu 已经确认是 swoole 的 bug swoole/swoole-src#3079 , swoole v4.4.16 已经修复该问题。
from mix.
我用的就是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.
多提交几次就会出现,我是一般第三次提交会出现,也有可能第二次出现。
from mix.
这个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.
@peinhu 我在 linux 用原生和框架都 ab 压测没有复现,这个问题不在处理
System Name: linux
PHP Version: 7.2.12
Swoole Version: 4.4.16
Framework Version: 2.1.15
from mix.
@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)
- Redis-subscribe 支持 prefix 否? HOT 1
- 没有对mysql保留关键字做反引号处理 HOT 1
- 2.2版本 UDP服务器会重复执行处理接收到的数据 HOT 2
- 官网无法访问 HOT 2
- PDO执行使用问号占位符的原生SQL报错 HOT 2
- 建议项目遵从语义化版本来维护版本号 HOT 1
- PHP用ip curl post请求 会卡1秒 HOT 5
- 新版本性能严重下降 HOT 6
- table方法传入表名order报错 HOT 1
- 验证器场景设置optional未生效 HOT 3
- Coroutine中同时使用Channel和Database pool导致出错 HOT 5
- mix-skeleton使用context()->get('guzzle') 报错 HOT 1
- php8RC3-swoole4.5.6 运行出错 HOT 1
- or and 查找抛出异常 HOT 1
- Upgrade to Zipkin 2.0 HOT 1
- log组件报错 HOT 1
- 推送模式卡死 HOT 1
- 如何正确的提交 PR
- V3 启动事务后 lastInsertId 值不正确 HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from mix.