我在我的简单CURL脚本中使用代理,该脚本通过https加载页面或json响应。一个IP代理最多只能同时限制3个连接。在大多数情况下,当我运行脚本3次时,它仅加载2页,而由于达到限制,代理服务器拒绝了第3页,因此CURL连接之一似乎仍然有效。
$header[0] = "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8";
$header[] = "Accept-Encoding: gzip, deflate, br";
$header[] = "Accept-Language: en-US;q=0.9,en;q=0.8";
$header[] = "Connection: keep-alive";
$header[] = "Upgrade-Insecure-Requests: 1";
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_HEADER, 0);
curl_setopt($curl, CURLOPT_HTTPHEADER, $header);
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($curl, CURLOPT_REFERER, $referer);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_BINARYTRANSFER, true);
curl_setopt($curl, CURLOPT_TIMEOUT, $timeout);
curl_setopt($curl, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($curl, CURLOPT_PROXY, $proxyIp);
curl_setopt($curl, CURLOPT_FRESH_CONNECT, true);
curl_setopt($curl, CURLOPT_FORBID_REUSE, true);
curl_setopt($curl, CURLOPT_NOSIGNAL, true);
curl_exec($curl);
$page = curl_close(curl);