简体   繁体   English

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

[英]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 找不到能解释我问题的简单代码

You can use a simple code by using curl 您可以使用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);
?>

it will test accessing Google from this proxy. 它将测试从此代理访问Google。

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. 但是,如果要测试多个代理,请使用for循环进行此操作。

Try this: 尝试这个:

class ListeningServerStub { protected $client; 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;
}

} }

How do I unit test socket code with PHPUnit? 如何使用PHPUnit对套接字代码进行单元测试?

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

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