繁体   English   中英

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

[英]How to test proxy or socks with php

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

218.36.xx.xxx:88xx

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

袜子工作打印还可以,如果没打印错我搜索了很多我

找不到能解释我问题的简单代码

您可以使用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。

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

<?

$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);
?>

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

尝试这个:

class ListeningServerStub {受保护的$ 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;
}

}

如何使用PHPUnit对套接字代码进行单元测试?

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM