Inheritance: extends Worker
Beispiel #1
0
 * @license http://www.opensource.org/licenses/mit-license.php MIT License
 */
use Workerman\Worker;
use Workerman\WebServer;
use Workerman\Protocols\Websocket;
// 自动加载类
require_once __DIR__ . '/../../Workerman/Autoloader.php';
$recv_worker = new Worker('Websocket://0.0.0.0:8080');
$recv_worker->onWorkerStart = function ($recv_worker) {
    $send_worker = new Worker('Websocket://0.0.0.0:8008');
    $send_worker->onMessage = function ($connection, $data) {
    };
    $recv_worker->sendWorker = $send_worker;
    $send_worker->listen();
};
$recv_worker->onMessage = function ($connection, $data) use($recv_worker) {
    foreach ($recv_worker->sendWorker->connections as $send_connection) {
        //$send_connection->websocketType = "\x82";
        $send_connection->send($data);
    }
};
// WebServer
$web = new WebServer("http://0.0.0.0:8088");
// WebServer数量
$web->count = 2;
// 设置站点根目录
$web->addRoot('www.your_domain.com', __DIR__ . '/Web');
// 如果不是在根目录启动,则运行runAll方法
if (!defined('GLOBAL_START')) {
    Worker::runAll();
}
<?php

/**
 * HTTP Server.
 */
require_once 'vendor/autoload.php';
use Workerman\WebServer;
$webServer = new WebServer('http://127.0.0.1:80');
$webServer->addRoot('localhost', 'public_html/');
WebServer::runAll();
Beispiel #3
0
/**
 * This file is part of workerman.
 *
 * Licensed under The MIT License
 * For full copyright and license information, please see the MIT-LICENSE.txt
 * Redistributions of files must retain the above copyright notice.
 *
 * @author walkor<*****@*****.**>
 * @copyright walkor<*****@*****.**>
 * @link http://www.workerman.net/
 * @license http://www.opensource.org/licenses/mit-license.php MIT License
 */
use Workerman\Worker;
use Workerman\WebServer;
use GatewayWorker\Gateway;
use GatewayWorker\BusinessWorker;
use Workerman\Autoloader;
// 自动加载类
require_once __DIR__ . '/../../Workerman/Autoloader.php';
Autoloader::setRootPath(__DIR__);
// WebServer
$web = new WebServer("http://0.0.0.0:55151");
// WebServer数量
$web->count = 2;
// 设置站点根目录
$web->addRoot('http://local.aiyeyun.com/', __DIR__ . '/Web');
// 如果不是在根目录启动,则运行runAll方法
if (!defined('GLOBAL_START')) {
    Worker::runAll();
}
Beispiel #4
0
                    $sender_io->to($to)->emit('new_msg', @$_POST['content']);
                    // 否则向所有uid推送数据
                } else {
                    $sender_io->emit('new_msg', @$_POST['content']);
                }
                // http接口返回ok
                return $http_connection->send('ok');
        }
        return $http_connection->send('fail');
    };
    // 执行监听
    $inner_http_worker->listen();
    // 一个定时器,定时向所有uid推送当前uid在线数及在线页面数
    Timer::add(1, function () {
        global $uidConnectionMap, $sender_io, $last_online_count, $last_online_page_count;
        $online_count_now = count($uidConnectionMap);
        $online_page_count_now = array_sum($uidConnectionMap);
        // 只有在客户端在线数变化了才广播,减少不必要的客户端通讯
        if ($last_online_count != $online_count_now || $last_online_page_count != $online_page_count_now) {
            $sender_io->emit('update_online_count', "当前<b>{$online_count_now}</b>人在线,共打开<b>{$online_page_count_now}</b>个页面");
            $last_online_count = $online_count_now;
            $last_online_page_count = $online_page_count_now;
        }
    });
});
// 启动一个webserver,用于吐html css js,方便展示
// 这个webserver服务不是必须的,可以将这些html css js文件放到你的项目下用nginx或者apache跑
$web = new WebServer('http://0.0.0.0:2123');
$web->addRoot('localhost', __DIR__ . '/web');
// 运行所有的服务
Worker::runAll();
Beispiel #5
0
        // add the client's username to the global list
        $usernames[$username] = $username;
        ++$numUsers;
        $socket->addedUser = true;
        $socket->emit('login', array('numUsers' => $numUsers));
        // echo globally (all clients) that a person has connected
        $socket->broadcast->emit('user joined', array('username' => $socket->username, 'numUsers' => $numUsers));
    });
    // when the client emits 'typing', we broadcast it to others
    $socket->on('typing', function () use($socket) {
        $socket->broadcast->emit('typing', array('username' => $socket->username));
    });
    // when the client emits 'stop typing', we broadcast it to others
    $socket->on('stop typing', function () use($socket) {
        $socket->broadcast->emit('stop typing', array('username' => $socket->username));
    });
    // when the user disconnects.. perform this
    $socket->on('disconnect', function () use($socket) {
        global $usernames, $numUsers;
        // remove the username from global usernames list
        if ($socket->addedUser) {
            unset($usernames[$socket->username]);
            --$numUsers;
            // echo globally that this client has left
            $socket->broadcast->emit('user left', array('username' => $socket->username, 'numUsers' => $numUsers));
        }
    });
});
$web = new WebServer('http://0.0.0.0:2022');
$web->addRoot('localhost', __DIR__ . '/public');
Worker::runAll();
Beispiel #6
0
<?php

/**
 * This file is part of workerman.
 *
 * Licensed under The MIT License
 * For full copyright and license information, please see the MIT-LICENSE.txt
 * Redistributions of files must retain the above copyright notice.
 *
 * @author walkor<*****@*****.**>
 * @copyright walkor<*****@*****.**>
 * @link http://www.workerman.net/
 * @license http://www.opensource.org/licenses/mit-license.php MIT License
 */
use Workerman\Worker;
use Workerman\WebServer;
use Workerman\Autoloader;
// autoload
require_once __DIR__ . '/../../Workerman/Autoloader.php';
Autoloader::setRootPath(__DIR__);
//@see http://doc3.workerman.net/advanced/webserver.html
$web_server = new WebServer("http://0.0.0.0:3737");
$web_server->name = 'SimpleChatWeb';
$web_server->count = 4;
$web_server->addRoot('example.com', __DIR__ . '/Web');
if (!defined('GLOBAL_START')) {
    Worker::runAll();
}
Beispiel #7
0
$gateway->onConnect = function($connection)
{
    $connection->onWebSocketConnect = function($connection , $http_header)
    {
        // 可以在这里判断连接来源是否合法,不合法就关掉连接
        // $_SERVER['HTTP_ORIGIN']标识来自哪个站点的页面发起的websocket链接
        if($_SERVER['HTTP_ORIGIN'] != 'http://kedou.workerman.net')
        {
            $connection->close();
        }
        // onWebSocketConnect 里面$_GET $_SERVER是可用的
        // var_dump($_GET, $_SERVER);
    };
}; 
*/
$webserver = new WebServer('http://0.0.0.0:80');
$webserver->addRoot('120.25.163.9', '/workerman/Applications/huicheng/Web');
$webserver->count = 1;
$webserver->onWorkerStart = function ($webserver) {
    //初始化多客服工号对应的昵称
    redisData::Set('HCS1@hc-information', '小汇');
    redisData::Set('HCS2@hc-information', '小承');
    redisData::Set('HCT1@hc-information', '小信');
    redisData::Set('HCT2@hc-information', '小息');
    //初始化定时间隔
    $time_interval = 7000;
    //初始化access_token
    transToWxServer::getaccess_token();
    transToWxServer::getjsapi_ticket();
    //定时获取access_token
    \Workerman\Lib\Timer::add($time_interval, function () {
// 心跳间隔
$gateway->pingInterval = 60;
//允许没有心跳回复次数
$gateway->pingNotResponseLimit = 2;
// 心跳数据
$gateway->pingData = '';
$gateway->registerAddress = '127.0.0.1:1236';
/* 
// 当客户端连接上来时,设置连接的onWebSocketConnect,即在websocket握手时的回调
$gateway->onConnect = function($connection)
{
    $connection->onWebSocketConnect = function($connection , $http_header)
    {
        // 可以在这里判断连接来源是否合法,不合法就关掉连接
        // $_SERVER['HTTP_ORIGIN']标识来自哪个站点的页面发起的websocket链接
        if($_SERVER['HTTP_ORIGIN'] != 'http://kedou.workerman.net')
        {
            $connection->close();
        }
        // onWebSocketConnect 里面$_GET $_SERVER是可用的
        // var_dump($_GET, $_SERVER);
    };
}; 
*/
$webserver = new WebServer('http://0.0.0.0:80');
$webserver->addRoot('120.25.148.172', '/hc_web_connection/Applications/WebController/Web');
$webserver->count = 1;
// 如果不是在根目录启动,则运行runAll方法
if (!defined('GLOBAL_START')) {
    Worker::runAll();
}
Beispiel #9
0
$gateway->onConnect = function($connection)
{
    $connection->onWebSocketConnect = function($connection , $http_header)
    {
        // 可以在这里判断连接来源是否合法,不合法就关掉连接
        // $_SERVER['HTTP_ORIGIN']标识来自哪个站点的页面发起的websocket链接
        if($_SERVER['HTTP_ORIGIN'] != 'http://chat.workerman.net')
        {
            $connection->close();
        }
        // onWebSocketConnect 里面$_GET $_SERVER是可用的
        // var_dump($_GET, $_SERVER);
    };
}; 
*/
// bussinessWorker 进程
$worker = new BusinessWorker();
// worker名称
$worker->name = 'ChatRoom';
// bussinessWorker进程数量
$worker->count = 4;
// WebServer
$web = new WebServer("http://0.0.0.0:33333");
// WebServer数量
$web->count = 2;
// 设置站点根目录
$web->addRoot('s2.chancemedia.com.cn', __DIR__ . '/Web');
// 如果不是在根目录启动,则运行runAll方法
if (!defined('GLOBAL_START')) {
    Worker::runAll();
}
Beispiel #10
0
/**
 * This file is part of workerman.
 *
 * Licensed under The MIT License
 * For full copyright and license information, please see the MIT-LICENSE.txt
 * Redistributions of files must retain the above copyright notice.
 *
 * @author walkor<*****@*****.**>
 * @copyright walkor<*****@*****.**>
 * @link http://www.workerman.net/
 * @license http://www.opensource.org/licenses/mit-license.php MIT License
 */
use Workerman\Worker;
use Workerman\WebServer;
use GatewayWorker\Gateway;
use GatewayWorker\BusinessWorker;
use Workerman\Autoloader;
// 自动加载类
require_once __DIR__ . '/../Workerman/Autoloader.php';
Autoloader::setRootPath(__DIR__);
// WebServer
$web = new WebServer("http://0.0.0.0:55151");
// WebServer数量
$web->count = 2;
// 设置站点根目录
$web->addRoot('http://local.aiyeyun.com/', '/admin/chat-room');
// 如果不是在根目录启动,则运行runAll方法
if (!defined('GLOBAL_START')) {
    Worker::runAll();
}