1 Star 0 Fork 0

Leiow/workerman

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
index.php 1.19 KB
一键复制 编辑 原始数据 按行查看 历史
Leiow 提交于 2017-11-13 01:41 . init pro
<?php
require 'vendor/autoload.php';
use Workerman\Worker;
$worker_path = realpath(__DIR__);
if (file_exists($worker_path . '/config/config.json')) {
$config = json_decode(file_get_contents($worker_path . '/config/config.json'), true);
} else {
exit('Can not find the configuration file!');
}
function record(\Workerman\Worker $worker, $msg)
{
if (Worker::$daemonize) {
Libs\Record::log($worker, $msg);
} else {
echo $msg, PHP_EOL;
}
}
$tcp_server = new Worker($config['tcp']['listen']);
$tcp_server->name = $config['tcp']['name'];
$tcp_server->count = $config['tcp']['process'];
$tcp_server->onConnect = function($conn) use ($tcp_server) {
$msg = 'New client connect : ' . $conn->getRemoteIp();
record($tcp_server, $msg);
};
$tcp_server->onMessage = function($conn, $data) {
echo 'Received: ', $data, PHP_EOL;
$conn->send('ok!!!!');
};
$tcp_server->onError = function($conn, $code, $msg) use ($tcp_server) {
$msg = 'Error code : ' . $code . '; message : ' . $msg;
record($tcp_server, $msg);
};
$tcp_server->onClose = function($conn) use ($tcp_server) {
$msg = $conn->getRemoteIp() . ' close!';
record($tcp_server, $msg);
};
Worker::runAll();
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
PHP
1
https://gitee.com/Leiow/workerman.git
[email protected]:Leiow/workerman.git
Leiow
workerman
workerman
master

搜索帮助