怎么在本地搭建网站,百度云主机上装网站,2023网页游戏大全,wordpress更换字体workman官网地址#xff1a;高性能PHP应用容器 workerman
1#xff1a;把workman项目放到linux服务器后#xff0c;需要启动你的php文件#xff0c;才可以使用 定位到项目根目录#xff1a;例#xff1a;cd /mnt/workman 启动代码#xff1a;php outin.php start -d 停…workman官网地址高性能PHP应用容器 workerman
1把workman项目放到linux服务器后需要启动你的php文件才可以使用 定位到项目根目录例cd /mnt/workman 启动代码php outin.php start -d 停止代码php outin.php stop 以debug调试方式启动 php outin.php start
2workman服务端写法
?phpuse Workerman\Worker;
use Workerman\Timer;
use Workerman\MySQL\Connection;
use procedure\Attendance;require_once __DIR__ . /vendor/autoload.php;$worker new Worker(websocket://0.0.0.0:8088);
Worker::$logFile /mnt/workman/log/outin.log; //日志地址$worker-uidConnetions [];
$worker-onConnect function($connection) use ($worker)
{$connection-onWebSocketConnect function($connection , $httpBuffer) use ($worker){// 可以在这里判断连接来源是否合法不合法就关掉连接// $_SERVER[HTTP_ORIGIN]标识来自哪个站点的页面发起的websocket连接
// if($_SERVER[HTTP_ORIGIN] ! https://www.workerman.net)
// {
// $connection-close();
// }// onWebSocketConnect 里面$_GET $_SERVER是可用的// var_dump($_GET, $_SERVER);//前端传入的参数可以根据typecompany_uuid判断需要显示的链接有哪些$worker-uidConnetions[$connection-id][connection] $connection;$worker-uidConnetions[$connection-id][type] $_GET[type];$worker-uidConnetions[$connection-id][company_uuid] $_GET[company_uuid];};
};$worker-onClose function ($connection) use ($worker)
{if (isset($connection-id)) {unset($worker-uidConnetions[$connection-id]);}
};// 进程启动后定时推送数据给客户端
$worker-onWorkerStart function($worker){//查表有需要的// file_put_contents(/mnt/workman/log/ .date(Ymd). .txt, date(Y-m-d H:i:s) . :jin .PHP_EOL, FILE_APPEND);$db new Connection(mysql地址,3306, root, password, 表名); //mysql链接信息$attend new Attendance();Timer::add(1, function()use($worker, $db, $attend){//10s之内的数据$time time() - 10;$time date(Y-m-d H:i:s,$time);//$time date(Y-m-d 00:00:00,$time);$infos $db-query(SELECT student_userid,class_name,student_name,sign_time,id,company_uuid,status,photo_url FROM sign WHERE tui 1 AND is_delete 0 AND sign_time $time GROUP BY student_userid ORDER BY id desc);//获取信息$attend_data $attend-getAttendanceData($db);foreach($worker-connections as $connection) {$res $worker-uidConnetions[$connection-id];file_put_contents(/mnt/workman/log/ .date(Ymd). .txt, date(Y-m-d H:i:s) . type1:.$res[type] .PHP_EOL, FILE_APPEND);//outin类型的使用本回调if ($res[type] outin) {foreach ($infos as $v) {$company_uuid $v[company_uuid];$student_userid $v[student_userid];$imgurl $db-single(SELECT imgurl FROM stu_face WHERE company_uuid $company_uuid AND student_userid $student_userid);if ($v[company_uuid] $res[company_uuid]) {$arr [class_name$v[class_name],student_name$v[student_name],status$v[status],photo_url$imgurl,sign_time$v[sign_time]];//打印输出查询的数据file_put_contents(/mnt/workman/log/ .date(Ymd). .txt, date(Y-m-d H:i:s) . xinxi:.json_encode($arr, true) .PHP_EOL, FILE_APPEND);//根据数据为已推送$db-query(UPDATE sign SET tui 2 WHERE tui 1 AND company_uuid $company_uuid AND student_userid $student_userid);$connection-send(json_encode($arr));}}}if ($res[type] banji) {$attend-banji($res, $attend_data[ban_infos],$db,$connection);}}});
};
Worker::runAll();2自动加载问题参考自动加载-workerman手册 注1文件名是小写的在使用命名空间的时候也是使用小写 2在需要使用的时候引入是这样的