如何使用 php 测试代理或袜子
Posted
技术标签:
【中文标题】如何使用 php 测试代理或袜子【英文标题】:How to test proxy or socks with php 【发布时间】:2014-03-08 02:56:54 【问题描述】:例如,如果我有代理或袜子:
218.36.xx.xxx:88xx
我如何编写代码以便测试袜子/代理是否正常工作,例如
socks work print ok if not print wrong 我搜索了很多我
没有找到解释我的问题的简单代码
【问题讨论】:
【参考方案1】:您可以使用这个简单的代码来测试一个代理:
<?
$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 循环来执行此操作。
【讨论】:
【参考方案2】:你可以通过 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。
【讨论】:
【参考方案3】:试试这个:
类 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 – 1024 bytes
$input = socket_read($client, 1024);
return $input;
How do I unit test socket code with phpUnit?
【讨论】:
以上是关于如何使用 php 测试代理或袜子的主要内容,如果未能解决你的问题,请参考以下文章
如何在命令行中使用带有 gradle 的袜子来解决依赖关系?