Search code examples
phpproxyconnectionsocks

Socks5 multiple requests


i'm using a socks5 php library that connects to a proxy and sends data through it. The library works when i do a single request to a http server, but when i do the second in receive empty string and at the third i receive an error

10053 An established connection was aborted by the software in your host machine.

I don't understand why that happens, i looked trought RFC and wikipedia about the socks5 server and i think all the connection is correct. But still don't get second response.

The library code is one file and i get it from here Socks5Socket

And my code is the next one

set_time_limit(100);
error_reporting ( E_ALL );

require_once "Socks5Socket.php";

$s = new \Socks5Socket\Client();
$s->configureProxy(array(
    'hostname' => '162.144.56.44',
    'port' => 60088
));
$s->connect('en.wikipedia.org', 80);
$request = "GET /wiki/HTTP_persistent_connection HTTP/1.1\r\n".
           "Host: en.wikipedia.org\r\nConnection: Keep-Alive\r\n\r\n";
$s->send($request);
$response = $s->readAll();

//At this point all OK



$request2 = "GET /wiki/No-till_farming HTTP/1.1\r\n".
           "Host: en.wikipedia.org\r\nConnection: Keep-Alive\r\n\r\n";

$s->send($request2);
// Empty string here, no error
$response2 = $s->readAll();


$s->send($request2);
// Errno 10053
$response3 = $s->readAll();
file_put_contents("response.txt",$response2);
$response = substr($response,strpos($response,"»")+1);
//echo $response;
echo "<br><br>".substr($response,strpos($response,"\r\n\r\n")+1);

Solution

  • Ok, the problem was that the http server was closing my connection before i could do anything else. I've tried with a SMTP server and the connection was no more closed.