Created
March 20, 2017 06:06
-
-
Save shin1x1/ba1a41ae0a4d7a4fd4d65f32819d2d82 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
const HOST = '49.212.25.40'; | |
const PORT = '80'; | |
function createStream() { | |
$errorNo = $errorMessage = null; | |
$stream = stream_socket_client(HOST . ':' . PORT, $errorNo, $errorMessage, 10); | |
if (!$stream) { | |
throw new \Exception($errorNo . ':', $errorMessage); | |
} | |
fwrite($stream, "GET /sleep.php HTTP/1.0\r\n\r\n"); | |
return $stream; | |
} | |
$streams = [ | |
createStream(), | |
createStream(), | |
createStream(), | |
]; | |
$write = $except = []; | |
while (count($streams) > 0) { | |
$read = $streams; | |
$ret = stream_select($read, $write, $except, 10); | |
if ($ret === false) { | |
throw new \Exception('error'); | |
} else if ($ret === 0) { | |
throw new \Exception('could not read'); | |
} else { | |
foreach ($read as $r) { | |
$i = array_search($r, $streams); | |
echo fread($r, 4096); | |
fclose($r); | |
unset($streams[$i]); | |
} | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment