本文整理汇总了PHP中select::bysocket方法的典型用法代码示例。如果您正苦于以下问题:PHP select::bysocket方法的具体用法?PHP select::bysocket怎么用?PHP select::bysocket使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类select
的用法示例。
在下文中一共展示了select::bysocket方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: socket_server
public function socket_server($port)
{
global $sockets, $groups, $master;
$main = new Group();
$main->port = $port;
$main->name = "Main";
$main->members = array();
$main->task = "chat";
array_push($groups, $main);
$master = connection::WebSocket($port);
$sockets = array($master);
while (true) {
$changed = $sockets;
$write = NULL;
$except = NULL;
socket_select($changed, $write, $except, NULL);
foreach ($changed as $socket) {
if ($socket == $master) {
$client_socket = socket_accept($master);
if ($client_socket < 0) {
continue;
} else {
connection::connect($client_socket);
}
} else {
$client = select::bysocket($socket);
$bytes_lenght = socket_recv($socket, $buffer, 2048, 0);
if ($bytes_lenght <= 6) {
connection::disconnect($client);
} else {
if ($client->status < 2) {
connection::dohandshake($client, $buffer);
} else {
$buffer = other::handle_data($buffer);
if ($client->status < 3) {
connection::login($client, $buffer);
} else {
if (true) {
chat::process($client, $buffer);
} else {
//nothing
}
}
}
}
}
}
chat::logm("run\n");
}
}