gpt4 book ai didi

php - 带有代理的PHP CURL在套接字上导致CLOSE_WAIT

转载 作者:行者123 更新时间:2023-12-03 11:55:09 25 4
gpt4 key购买 nike

我正在使用PHP curl库来建立连接并从WEB检索内容(通常如此)。

我有多个SOCKS5代理服务器在本地主机上运行,​​端口从10300到10350,PHP随机选择一个端口。

我的代码:

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_PROXY, "localhost:".mt_rand(10300, 10350));
curl_setopt($ch, CURLOPT_PROXYTYPE, CURLPROXY_SOCKS5);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$curl_resp = curl_exec($ch);
curl_close($ch);
/// ... whatever logic

但是,如果我长时间将此代码放入循环中,则会收到错误消息,提示无法打开更多文件。我在线阅读这是因为达到了文件处理程序限制,因此我使用 lsof -p进行了调试,我注意到该过程有成百上千的这些行:
... TCP localhost:43030->localhost:10303 (CLOSE_WAIT)
... TCP localhost:40982->localhost:10341 (CLOSE_WAIT)
... TCP localhost:48718->localhost:10304 (CLOSE_WAIT)
... TCP localhost:41655->localhost:10350 (CLOSE_WAIT)
... TCP localhost:41915->localhost:10310 (CLOSE_WAIT)
... TCP localhost:49746->localhost:10322 (ESTABLISHED)

我正在研究为什么会这样,但是我不明白,因为我正在调用 curl_close,并且我认为CURL也将关闭PROXY连接,或者我丢失了什么?

版本:
PHP 7.1.4-1+deb.sury.org~trusty+1 (cli) (built: Apr 11 2017 22:45:20) (NTS)
curl 7.52.1 (x86_64-pc-linux-gnu) libcurl/7.52.1 OpenSSL/1.0.1f zlib/1.2.8 libidn2/0.9 libpsl/0.11.0 (+libicu/52.1) libssh2/1.4.3 nghttp2/1.19.0 librtmp/2.3

最佳答案

我也遇到了这个问题。解决方法是添加

curl_setopt($ch, CURLOPT_HTTPHEADER, array("Connection: close"));

起初我以为与php7有关,因为我可以在php7盒上重现它,但在php5上却不会发生。不幸的是,我在另一个php7盒上尝试过,也没有再发生。因此,我仍然对根本原因感到困惑。

关于php - 带有代理的PHP CURL在套接字上导致CLOSE_WAIT,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43899382/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com