Comments (8)
感觉你写的更加合理点。
from workerman.
- 你这代码看似完整性,但功能来说他那个没问题的,你失去了可读性。
- 如何解决这问题,添加一行英文注释说明下10的含义就行了。
from workerman.
- 你这代码看似完整性,但功能来说他那个没问题的,你失去了可读性。
- 如何解决这问题,添加一行英文注释说明下10的含义就行了。
源代码是$length += (int)substr($header, $pos + 18, 10);
截取了10个字符长度,应该不正确,不一定是10个字符长度呢,然后强制转换为int,如果不强制转换的话,有可能截取到的结果是999\nxxx
workerman/src/Protocols/Http.php
Lines 133 to 139 in 1c24fe4
两个判断重复,第一个强制截取了10个字节,第二个好像永远不会执行。
from workerman.
- 你这代码看似完整性,但功能来说他那个没问题的,你失去了可读性。
- 如何解决这问题,添加一行英文注释说明下10的含义就行了。
源代码是
$length += (int)substr($header, $pos + 18, 10);
截取了10个字符长度,应该不正确,不一定是10个字符长度呢,然后强制转换为int,如果不强制转换的话,有可能截取到的结果是999\nxxx
int 32 位最大才多少,他这个极限是999999999字节,你见过这么大的网页文本(9G)?
截取到字符串的情况,强制转换int类型他不是已经处理这情况了?(int) substr(xxx);
from workerman.
- 你这代码看似完整性,但功能来说他那个没问题的,你失去了可读性。
- 如何解决这问题,添加一行英文注释说明下10的含义就行了。
源代码是
$length += (int)substr($header, $pos + 18, 10);
截取了10个字符长度,应该不正确,不一定是10个字符长度呢,然后强制转换为int,如果不强制转换的话,有可能截取到的结果是999\nxxx
int 32 位最大才多少,他这个极限是999999999字节,你见过这么大的网页文本(9G)? 截取到字符串的情况,强制转换int类型他不是已经处理这情况了?(int) substr(xxx);
你这么说确实没问题,但我忘记是因为什么发现的这个bug了,这行代码报过错~_~
from workerman.
- 你这代码看似完整性,但功能来说他那个没问题的,你失去了可读性。
- 如何解决这问题,添加一行英文注释说明下10的含义就行了。
源代码是
$length += (int)substr($header, $pos + 18, 10);
截取了10个字符长度,应该不正确,不一定是10个字符长度呢,然后强制转换为int,如果不强制转换的话,有可能截取到的结果是999\nxxx
复现问题给作者,然后pr修复一下。你这样写作者应该不会采取的(增加开销不说,可读性差太多了。)
from workerman.
标准http报文测试没有问题
<?php
$header = "HTTP/1.1 200 OK \r\nAccess-Control-Allow-Methods: POST, GET \r\nAccess-Control-Allow-Origin: https://www.baidu.com"." \r\nContent-Length: 105 \r\nContent-Type: application/json; charset=utf-8\r\n\r\n";
$pos = strpos($header, "\r\nContent-Length: ");
$value = substr($header, $pos + 18, 10);
$length = (int)$value;
var_dump($value, $length, $length === 105);
输出结果:
string(10) "105
Cont"
int(105)
bool(true)
from workerman.
有些看似不合理的代码,实则很巧妙,当然你的出发点也是没错的,更加严谨。
from workerman.
Related Issues (20)
- change worker after onMessage event HOT 3
- Question: What http workers do ? HOT 1
- How to start script many times at same time HOT 2
- Kill worker in linux HOT 4
- From Ratchet to Workerman HOT 1
- Error package because of receiving data before handshake HOT 3
- Restrict access by origin domain and limit the number of connections HOT 1
- Implementation of the onError() handler HOT 1
- Param sameSite in the $response->cookie() should be a string HOT 1
- [WSL] 开发环境退出 webman 时出现死循环 HOT 8
- Why sse server sometimes can stop itself and how to prevent it?
- How to run 2 websockets in different classes? HOT 1
- Websocket worker's onMessage doesn't intercept ping requests. HOT 3
- 有的客户端获取count($globalWorker->connections) 有时候是1 HOT 1
- Question: docker and debug/daemon mode HOT 2
- Feature request: openswoole support HOT 1
- Timer::add in master process is impossible ? I think it can be HOT 1
- Use internal PHP to parse post data HOT 1
- Using this as Radius Server HOT 7
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 workerman.