如何使用php测试代理或袜子

时间:2014-03-08 02:56:55

标签: php proxy socks

例如,如果我有代理或袜子:

218.36.xx.xxx:88xx

我如何编写代码以便我可以测试socks / proxy是否正常工作,例如

袜子工作打印好如果没有打印错误我搜索了很多我

没有找到解释我的问题的简单代码

3 个答案:

答案 0 :(得分:1)

您可以使用curl

来使用简单的代码
<?
$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);
?>

它将测试从此代理访问Google。

答案 1 :(得分:1)

您可以使用此简单代码测试一个代理:

\n

但是,如果要测试多个代理,请使用for循环来执行此操作。

答案 2 :(得分:0)

试试这个:

类ListeningServerStub {     protected $ client;

public function listen()
{
    $sock = socket_create(AF_INET, SOCK_STREAM, 0);

    // Bind the socket to an address/port
    socket_bind($sock, 'localhost', 0) or throw new RuntimeException('Could not bind to address');

    // Start listening for connections
    socket_listen($sock);

    // Accept incoming requests and handle them as child processes.
    $this->client = socket_accept($sock);
}

public function read()
{
    // Read the input from the client &#8211; 1024 bytes
    $input = socket_read($client, 1024);
    return $input;
}

}

How do I unit test socket code with PHPUnit?