46 lines
1.5 KiB
PHP
46 lines
1.5 KiB
PHP
<?php
|
|
// +----------------------------------------------------------------------
|
|
// | 萤火商城系统 [ 致力于通过产品和服务,帮助商家高效化开拓市场 ]
|
|
// +----------------------------------------------------------------------
|
|
// | Copyright (c) 2017~2023 https://www.yiovo.com All rights reserved.
|
|
// +----------------------------------------------------------------------
|
|
// | Licensed 这不是一个自由软件,不允许对程序代码以任何形式任何目的的再发行
|
|
// +----------------------------------------------------------------------
|
|
// | Author: 萤火科技 <admin@yiovo.com>
|
|
// +----------------------------------------------------------------------
|
|
declare (strict_types=1);
|
|
|
|
namespace app\store\controller;
|
|
use think\facade\Db;
|
|
use think\worker\Server;
|
|
use Workerman\Lib\Timer;
|
|
define('HEARTBEAT_TIME', 20);// 心跳间隔55秒
|
|
class Worker extends Server
|
|
{
|
|
protected $socket = 'websocket://0.0.0.0:2345';
|
|
public function __construct()
|
|
{
|
|
parent::__construct();
|
|
$this->onMessage();
|
|
// 或者这样调用
|
|
$this->worker->onWorkerStart = function($worker)
|
|
{
|
|
echo "Worker starting...\n";
|
|
};
|
|
}
|
|
/**
|
|
* 收到信息
|
|
* @param $connection
|
|
* @param $data
|
|
*/
|
|
public function onMessage()
|
|
{
|
|
$this->worker->onMessage = function($connection, $data)
|
|
{
|
|
dump('参数:'.$data.'时间:'.date('Y-m-d H:i:s',time()));
|
|
$connection->send($data);
|
|
};
|
|
}
|
|
}
|
|
|