use Workerman\Worker;
/** * 这是官方的一个聊天实例 */ require_once 'Workerman/Autoloader.php'; $global_uid = 0; $text_worker = null; // 有客户端连接上来 function handler_connection($connection) { global $global_uid; $connection->uid = ++$global_uid; } // 客户端有数据发过来 function handler_message($connection, $data) { global $text_worker; foreach($text_worker->connections as $conn) { $conn->send("User[{$connection->uid}] said: $data .\r\n"); } } // 有客户端关闭 function handler_close($connection) { global $text_worker; foreach($text_worker->connections as $conn) { $conn->send("User[{$connection->uid}] Logout.\r\n"); } } $text_worker = new Worker("Text://0.0.0.0:2345"); $text_worker->count = 1; $text_worker->name = 'textWorker'; $text_worker->onConnect = 'handler_connection'; $text_worker->onMessage = 'handler_message'; $text_worker->onClose = 'handler_close'; Worker::runAll();
查看更多关于Workerman3.x 版本学习之入门[转]的详细内容...
声明:本文来自网络,不代表【好得很程序员自学网】立场,转载请注明出处:http://haodehen.cn/did31397