[PHP] 使用curl扩展POST或者PUT时数据不全和连接中断的排查
2023-02-18 15:41:24 时间
在项目中使用到了curl扩展进行PUT传递数据到另一个接口,但是看到的现象是有时候偶发数据是空的 .
这个时候就使用了tcpdump命令来查看连接情况
具体命令是下面 , 另一个接口的端口号是8025 :
tcpdump -i any port 8025 -l -s 0
可以看到在我请求对方时出现下面这个TCP标志位 , R RST是中断连接
Flags [R], seq 1525906647, win 0, length 0
这就说明是我这边的问题, 我这边中断了连接
排查代码看到了有设置超时时间
public function setTimeout($timeout) { if (is_null($timeout)) { return; } $t = intval($timeout); if ($t >= 0 && $t < ini_get('default_socket_timeout')) { $this->timeout = $t; } }
最终设置的是curl扩展的配置超时时间项
if ($this->timeout > 0) { $opts[CURLOPT_TIMEOUT] = $this->timeout; }
当我设置的超时时间超过php.ini中 default_socket_timeout 60秒时 , 就使用这个类里面的默认的超时时间 , 而类里面写的是2秒
因此引发了上面连接中断的问题.
相关文章
- 3xx HTTP状态码的终极指南
- React报错之React.Children.only expected to receive single React element child
- React报错之Element type is invalid
- React报错之Too many re-renders
- React报错之Function components cannot have string refs
- 如何发布一个 TypeScript 编写的 npm 包
- 如何使用zx编写shell脚本
- 13个构建RESTful API的最佳实践
- 什么是REST API
- React报错之Rendered more hooks than during the previous render
- 如何使用CSS伪类选择器
- React报错之Property 'value' does not exist on type EventTarget
- React报错之Parameter 'event' implicitly has an 'any' type
- React报错之Parameter 'props' implicitly has an 'any' type
- React报错之Property 'value' does not exist on type 'HTMLElement'
- React报错之You provided a `checked` prop to a form field
- React报错之Invalid hook call
- React报错之React hook 'useState' cannot be called in a class component
- React报错之React Hook 'useEffect' is called in function
- React报错之React hook 'useState' is called conditionally