curl扩展POST 或者PUT [PHP]

项目中使用到了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) {\n        if (is_null($timeout)) {\n            return;\n        }\n        $t = intval($timeout);\n        if ($t >= 0 && $t < ini_get(\'default_socket_timeout\')) {\n            $this->timeout = $t;\n        }\n    }

最终设置的是curl扩展的配置超时时间项

        if ($this->timeout > 0) {\n            $opts[CURLOPT_TIMEOUT] = $this->timeout;\n        }

当我设置的超时时间超过php.ini中 default_socket_timeout 60秒时 , 就使用这个类里面的默认的超时时间 , 而类里面写的是2秒

因此引发了上面连接中断的问题.

发表回复