-
Notifications
You must be signed in to change notification settings - Fork 0
/
io.php
36 lines (29 loc) · 922 Bytes
/
io.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
<?php
$streamList = [
stream_socket_client('tcp://localhost:8080'),
stream_socket_client('tcp://localhost:8001'),
fopen('arquivo.txt','r'),
fopen('arquivo2.txt','r'),
];
fwrite($streamList[0],'GET /http-server.php HTTP/1.1' . PHP_EOL . PHP_EOL);
foreach($streamList as $stream){
stream_set_blocking($stream,false);
}
do {
$copyReadStream = $streamList;
$numeroDeStreams = stream_select($copyReadStream,$write,$except,0,200000);
if($numeroDeStreams === 0){
continue;
}
foreach ($copyReadStream as $key => $stream){
$conteudo = stream_get_contents($stream);
$posicaoFimHttp = strpos($conteudo, "\r\n\r\n");
if($posicaoFimHttp !== false){
echo substr($conteudo, $posicaoFimHttp + 4);
}else{
echo $conteudo;
}
unset($streamList[$key]);
}
} while (!empty($streamList));
echo "Li todos" . PHP_EOL;