ext-uv/examples/fingerd.php

42 lines
1.0 KiB
PHP
Raw Normal View History

2012-06-02 18:46:34 +02:00
<?php
$tcp = uv_tcp_init();
uv_tcp_bind($tcp, uv_ip4_addr('0.0.0.0',79));
$users = array(
array(
"username" => "chobie",
"name" => "Shuhei Tanuma",
"twitter" => "chobi_e",
),
);
function pad($str)
{
return str_pad($str, 20, ' ',STR_PAD_RIGHT);
}
2020-02-15 22:36:03 +01:00
uv_listen($tcp, 100, function($server) use ($users) {
2012-06-02 18:46:34 +02:00
$client = uv_tcp_init();
uv_accept($server, $client);
2020-02-15 22:36:03 +01:00
uv_read_start($client, function($socket, $buffer) use ($users){
2012-06-02 18:46:34 +02:00
$buffer = str_replace("/W","",$buffer);
if ($buffer == "\r\n") {
$data = "";
$keys = array("Login","Name","Twitter");
$data .= join("",array_map("pad",$keys)) . "\r\n";
foreach($users as $user) {
$data .= join("", array_map("pad",array_values($user))) . "\r\n";
}
2020-02-15 22:36:03 +01:00
uv_write($socket, $data, function($client, $stat) {
2012-06-02 18:46:34 +02:00
uv_close($client);
});
} else {
var_dump($buffer);
uv_close($socket);
}
});
});
2020-02-15 22:36:03 +01:00
uv_run();