Pergunta

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

Foi útil?

Solução

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.

Outras dicas

You can use a simple code by using 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.

Try this:

class 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?

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top