How does php curl use proxy ip to grab data?

I plan to use proxy ip to grab data according to the following code, but it always fails. I don"t know why?

php the core code of the application agent is as follows:

curl_setopt_array([
    CURLOPT_HTTPPROXYTUNNEL => true , 
    // 
    CURLOPT_PROXYAUTH => CURLAUTH_BASIC , 
    // 
    CURLOPT_PROXYTYPE => CURLPROXY_HTTP ,
    // ip
    CURLOPT_PROXY => "106.75.164.15" , 
    // 
    CURLOPT_PROXYPORT => 3128
]);

my agent is obtained from West thorn free agent IP http agent, none of which can grab data normally!

how can curl use proxy ip to grab data?

< H2 > the complete code is as follows < / H2 >

Agent ip list

[
    [
        "ip" => "106.75.164.15" ,
        "port" => "3128" ,
        "type" => CURLPROXY_HTTP ,
    ] ,
    [
        "ip" => "221.237.51.128" ,
        "port" => "31447" ,
        "type" => CURLPROXY_HTTP
    ] ,
    [
        "ip" => "60.169.220.111" ,
        "port" => "808" ,
        "type" => CURLPROXY_HTTP
    ] ,
    [
        "ip" => "221.6.138.154" ,
        "port" => "30893" ,
        "type" => CURLPROXY_HTTP
    ] ,
    [
        "ip" => "223.84.179.198" ,
        "port" => "58202" ,
        "type" => CURLPROXY_HTTP
    ]
]

grab code

function ajax($url , $data = [] , $header = []){
    static $loop_count = 0;
    static $disabled   = [];

    if (empty($url)) {
        throw new Exception(" url");
    }

    $ip_list = config("app.proxy");
    if ($loop_count == 0) {
        foreach ($ip_list as $v)
        {
            if (in_array($v["ip"] . ":" .  $v["port"] , $disabled)) {
                $loop_countPP;
                continue ;
            }
        }
    }
    if (!isset($ip_list[$loop_count])) {
        exit(" ip ");
    }

    $url = is_string($url) ? $url : $url["url"];
    $method = is_string($url) ? "get" : strtolower($url["method"]);
    $res = curl_init();
    $cur = $ip_list[$loop_count];

    curl_setopt_array($res , [
        CURLOPT_RETURNTRANSFER => true ,
        CURLOPT_HEADER => false ,
        CURLOPT_URL => $url ,
        // 
        CURLOPT_HTTPHEADER => $header ,
        CURLOPT_POST => $method == "post" ,
        CURLOPT_POSTFIELDS => $data,
        // user-agent 
        CURLOPT_USERAGENT => "Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/69.0.3497.100 Safari/537.36" ,
        //  cookie
        CURLOPT_COOKIE => "_lxsdk_cuid=166527efb46c8-09383c52b934ce-333b5602-1fa400-166527efb46c8; _lxsdk=166527efb46c8-09383c52b934ce-333b5602-1fa400-166527efb46c8; _hc.v=46801334-09d9-22c2-4af0-c28dc5058ce4.1538982346; aburl=1; _lx_utm=utm_source%3DBaidu%26utm_medium%3Dorganic; s_ViewType=10; cy=261; cye=anshun; _lxsdk_s=166527efb48-047-aa7-f72%7C%7C574" ,
        CURLOPT_SSL_VERIFYPEER => false ,

        //  http 
        CURLOPT_HTTPPROXYTUNNEL => true ,
        CURLOPT_PROXYAUTH => CURLAUTH_BASIC ,
        CURLOPT_PROXYTYPE   => $cur["type"] ,
        CURLOPT_PROXY       => $cur["ip"] ,
        CURLOPT_PROXYPORT   => $cur["port"] ,
    ]);

    $str = curl_exec($res);
    if ($str == false) {
        $disabled[] = $cur["ip"] . ":" . $cur["port"];
        $loop_countPP;
        return ajax($url , $data , $header);
    }
    return $str;
}
Aug.09,2021

ip is banned?

Menu