本文整理汇总了PHP中swoole_server类的典型用法代码示例。如果您正苦于以下问题:PHP swoole_server类的具体用法?PHP swoole_server怎么用?PHP swoole_server使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了swoole_server类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的PHP代码示例。
示例1: my_onReceive
function my_onReceive(swoole_server $serv, $fd, $from_id, $data)
{
//var_dump($serv->connection_info($fd, $from_id));
//echo "worker_pid=".posix_getpid().PHP_EOL;
//var_dump($fd, $from_id);
$serv->send($fd, 'Swoole: ' . $data, $from_id);
}
开发者ID:sophia2152,项目名称:swoole-src,代码行数:7,代码来源:udp.php
示例2: onReceive
public function onReceive(swoole_server $serv, $fd, $from_id, $data)
{
echo "Get Message From Client {$fd}:{$data}\n";
$this->test = new Test();
var_dump($this->test);
$serv->task(serialize($this->test));
}
开发者ID:jinchunguang,项目名称:swoole-doc,代码行数:7,代码来源:Server.php
示例3: my_onTask
function my_onTask(swoole_server $serv, $task_id, $from_id, $data)
{
static $datas = array();
if (isset($data['cmd'])) {
switch ($data['cmd']) {
case 'get':
$key = $data['key'];
$val = isset($datas[$key]) ? $datas[$key] : "";
$serv->finish(array('key' => $key, 'val' => $val));
break;
case "set":
$key = $data['key'];
$val = $data['val'] . "_" . $from_id;
$datas[$key] = $val;
return;
break;
case "del":
$key = $data['key'];
if (isset($datas[$key])) {
unset($datas[$key]);
}
break;
case "task":
$key = $data['key'];
echo "Do task " . $key . PHP_EOL;
break;
}
}
echo "AsyncTask[PID=" . posix_getpid() . "]: task_id={$task_id}." . PHP_EOL;
// $serv->finish("OK");
}
开发者ID:liangkwok,项目名称:Swoole,代码行数:31,代码来源:shared_server.php
示例4: onReceive
public function onReceive(swoole_server $serv, $fd, $from_id, $data)
{
echo "Get Message from client {$fd}:{$data}:{$from_id}\n";
$params = array('fd' => $fd, 'file' => $data);
$id = $serv->task(json_encode($params));
echo "Continue Handle Worker {$id}\n";
}
开发者ID:shijl,项目名称:swoole,代码行数:7,代码来源:server.php
示例5: onReceive
public function onReceive(swoole_server $serv, $fd, $from_id, $data)
{
echo "Get Message From Client {$fd}:{$data}\n";
$param = array('fd' => $fd, 'msg' => $data);
$str = json_encode($param);
$serv->after(1000, array($this, 'onAfter'), $str);
}
开发者ID:ppker,项目名称:swoole-doc,代码行数:7,代码来源:swoole_after_server.php
示例6: my_onReceive
function my_onReceive(swoole_server $serv, $fd, $from_id, $data)
{
$cmd = trim($data);
if ($cmd == "reload") {
$serv->reload($serv);
} elseif ($cmd == "task") {
$task_id = $serv->task("hello world", 0);
echo "Dispath AsyncTask: id={$task_id}\n";
} elseif ($cmd == "info") {
$info = $serv->connection_info($fd);
$serv->send($fd, 'Info: ' . var_export($info, true) . PHP_EOL);
} elseif ($cmd == "broadcast") {
$start_fd = 0;
while (true) {
$conn_list = $serv->connection_list($start_fd, 10);
if ($conn_list === false) {
break;
}
$start_fd = end($conn_list);
foreach ($conn_list as $conn) {
if ($conn === $fd) {
continue;
}
$serv->send($conn, "hello from {$fd}\n");
}
}
} elseif ($cmd == "error") {
hello_no_exists();
} elseif ($cmd == "shutdown") {
$serv->shutdown();
} else {
$serv->send($fd, 'Server Receive: ' . $data . PHP_EOL, $from_id);
$data = json_decode($data, true);
if (isset($data['cmd'])) {
switch ($data['cmd']) {
case 'get':
$key = $data['key'];
$result = $serv->taskwait(json_encode($data), 0.5, 0);
$serv->send($fd, "get {$key}:" . $result . PHP_EOL);
break;
case "set":
$serv->task(json_encode($data), 0);
$serv->send($fd, "ok" . PHP_EOL);
break;
case "del":
$serv->task(json_encode($data), 0);
break;
case "reload":
break;
default:
echo "server:" . $data . PHP_EOL;
}
}
//$serv->close($fd);
}
//echo "Client:Data. fd=$fd|from_id=$from_id|data=$data";
//$serv->deltimer(800);
//swoole_server_send($serv, $other_fd, "Server: $data", $other_from_id);
}
开发者ID:xxoxx,项目名称:gitswoolestudy,代码行数:59,代码来源:task_shared_serv.php
示例7: process
public function process(swoole_server $serv, $taskId, $fromId, $data)
{
// model load
$this->defaultModel->sayHello();
// library load
$this->mcurl->isEnable();
$serv->finish('sync ok!');
}
开发者ID:ErosZy,项目名称:CSF,代码行数:8,代码来源:SyncTask.php
示例8: onReceive
public function onReceive(swoole_server $serv, $fd, $from_id, $data)
{
echo "Get Message From Client {$fd}:{$data}\n";
// send a task to task worker.
$param = array('fd' => $fd, 'source' => $data);
$serv->task(json_encode($param));
echo "Continue Handle Worker\n";
}
开发者ID:CptSteven,项目名称:faster-rcnn-mod,代码行数:8,代码来源:train.php
示例9: serve
function serve()
{
$serv = new \swoole_server(SERVERHOST, SERVERPORT);
$serv->on('workerStart', [$this, 'onStart']);
$serv->on('receive', [$this, 'onReceive']);
$serv->set(array('worker_num' => 1, 'dispatch_mode' => 1, 'open_length_check' => true, 'package_max_length' => 8192000, 'package_length_type' => 'N', 'package_length_offset' => 0, 'package_body_offset' => 4));
$serv->start();
}
开发者ID:qieangel2013,项目名称:zys,代码行数:8,代码来源:RpcServer.php
示例10: __construct
public function __construct($host, $ip, $config, $bufferDriverClass)
{
$server = new \swoole_server($host, $ip, SWOOLE_PROCESS, SWOOLE_SOCK_TCP);
$server->set($config);
$server->on('receive', array($this, 'onReceive'));
$server->on('close', array($this, 'onClose'));
$this->server =& $server;
$this->bufferDriverClass = $bufferDriverClass;
}
开发者ID:ehovel,项目名称:fatty,代码行数:9,代码来源:SwooleServer.php
示例11: onReceive
public function onReceive(swoole_server $serv, $fd, $from_id, $data)
{
$info = $serv->connection_info($fd, $from_id);
if ($info['server_port'] == 9502) {
$serv->send($fd, "welcom Admin \n");
} else {
$serv->send($fd, 'Swoole:' . $data);
}
}
开发者ID:alenslan,项目名称:nanshan,代码行数:9,代码来源:multi_port.php
示例12: onReceive
public function onReceive(swoole_server $serv, $fd, $from_id, $data)
{
echo "Get Message From Client {$fd}:{$data}\n";
foreach ($serv->connections as $client) {
if ($fd != $client) {
$serv->send($client, $data);
}
}
}
开发者ID:jinchunguang,项目名称:swoole-doc,代码行数:9,代码来源:chat_server.php
示例13: onConnect
public function onConnect(swoole_server $serv, $fd, $from_id)
{
//获取连接的客户端信息
$fdInfo = $serv->connection_info($fd);
echo '<pre>';
print_r($fdInfo);
echo '</pre>';
$serv->send($fd, "Welcome {$fd} Connect Server");
}
开发者ID:stonegithubs,项目名称:swoole-game,代码行数:9,代码来源:server.php
示例14: run
function run()
{
$serv = new swoole_server("127.0.0.1", 8002);
$serv->set(array('timeout' => 1, 'poll_thread_num' => 1, 'worker_num' => 1, 'backlog' => 128, 'max_conn' => 10000, 'dispatch_mode' => 2));
$serv->on('Receive', array($this, 'onReceive'));
$serv->on('Close', array($this, 'onClose'));
//swoole_server_addtimer($serv, 2);
#swoole_server_addtimer($serv, 10);
$serv->start();
}
开发者ID:jinguanio,项目名称:david,代码行数:10,代码来源:serv.php
示例15: onReceive
function onReceive(swoole_server $serv, $fd, $from_id, $data)
{
$this->count[$fd]++;
echo "Client#{$fd} recv: {$data}\n";
if ($this->count[$fd] > 10) {
$serv->close($fd);
} else {
$serv->send($fd, "hello client");
}
}
开发者ID:sophia2152,项目名称:swoole-src,代码行数:10,代码来源:reconnect_server.php
示例16: onReceive
public function onReceive(swoole_server $server, $fd, $from_id, $data)
{
if (empty($data)) {
// 发送数据给客户端,请求包错误
$data = array('code' => 500, 'msg' => '非法请求', 'data' => null);
$server->send($fd, json_encode($data));
}
//局域网管理
$udpClient = $server->connection_info($fd, $from_id);
if ($udpClient['server_port'] == '9502') {
$data = str_replace("\r\n\r\n", "", $data);
switch ($data) {
case 'stop':
echo '服务器关闭: ' . date('Y-m-d H:i:s') . PHP_EOL;
$server->shutdown();
$server->send($fd, '服务器关闭成功');
break;
case 'reload':
echo 'Worker进程重启: ' . date('Y-m-d H:i:s') . PHP_EOL;
$server->reload();
$server->send($fd, '服务器Worker重启成功');
break;
default:
$server->send($fd, '非法请求');
break;
}
} else {
$data = json_decode($data, true);
echo $data['name'] . " say hello " . Test::WORD . "\n";
$server->send($fd, $data['name'] . " say hello " . Test::WORD);
}
}
开发者ID:sukui,项目名称:swoole_auto_reload,代码行数:32,代码来源:server.php
示例17: run
function run($_setting = array())
{
$default_setting = array('dispatch_mode' => 3, 'max_request' => 0, 'open_eof_split' => true, 'package_eof' => self::EOF);
define('SWOOLE_SERVER', true);
$setting = array_merge($default_setting, $_setting);
$serv = new \swoole_server('0.0.0.0', self::PORT, SWOOLE_PROCESS);
$serv->set($setting);
$serv->on('receive', array($this, 'onReceive'));
$this->serv = $serv;
$this->serv->start();
}
开发者ID:google2013,项目名称:StatsCenter,代码行数:11,代码来源:LogServer2.php
示例18: onReceive
public function onReceive(swoole_server $serv, $fd, $from_id, $data)
{
$request = unpack("N", $data);
print_r($request);
$length = $request[1];
$cmd = $request[2];
$filename = substr($data, -$length);
echo "length = {$length}\n";
echo "{$filename}\n";
$serv->sendfile($fd, __DIR__ . "/" . $filename);
}
开发者ID:hytzxd,项目名称:swoole-doc,代码行数:11,代码来源:swoole_sendfile_server.php
示例19: __construct
public function __construct()
{
//初始化应用
$this->initializationOfApp();
// 创建swoole_http_server对象
$server = new swoole_server("0.0.0.0", 9500);
$server->on('connect', array($this, 'onConnect'));
$server->on('receive', array($this, 'onReceive'));
$server->on('close', array($this, 'onClose'));
$server->start();
}
开发者ID:jhomephper,项目名称:phalcon_swoole,代码行数:11,代码来源:TcpServer.php
示例20: run
function run($_setting = array())
{
$default_setting = array('worker_num' => 4, 'open_eof_check' => true, 'open_eof_split' => true, 'package_eof' => self::EOF);
$this->pid_file = $_setting['pid_file'];
$setting = array_merge($default_setting, $_setting);
$serv = new \swoole_server('0.0.0.0', self::SVR_PORT_AOP, SWOOLE_PROCESS, SWOOLE_TCP);
$serv->set($setting);
$serv->on('receive', array($this, 'onReceive'));
$this->serv = $serv;
$this->serv->start();
}
开发者ID:google2013,项目名称:StatsCenter,代码行数:11,代码来源:AopNetServer.php
注:本文中的swoole_server类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论