Search code examples
phpproxysocks

How to test proxy or socks with php


For example if I have a proxy or socks:

218.36.xx.xxx:88xx

How I can write the code so I can test if the socks/proxy is working or not, for example if the

socks work print ok if not print wrong I searched a lot I

didn't find s simple code that explain my issue


Solution

  • You can use this simple code to test one proxy:

    <?
    
    $ip   = "192.168.1.1";
    $port = "80";
    $curl = curl_init();
    CURL_SETOPT($curl,CURLOPT_URL,"http://google.fr");
    CURL_SETOPT($curl,CURLOPT_PROXY,$ip.":".$port);
    CURL_SETOPT($curl,CURLOPT_PROXYTYPE,CURLPROXY_HTTP);
    CURL_SETOPT($curl,CURLOPT_TIMEOUT,20);
    CURL_SETOPT($curl,CURLOPT_RETURNTRANSFER,True);
    CURL_SETOPT($curl,CURLOPT_FOLLOWLOCATION,True);
    curl_exec($curl);
    curl_close($curl);
    ?>
    

    However, if you want to test multiple proxies, use the for loop to do that.