当前位置: 首页>>代码示例>>PHP>>正文


PHP swoole_server::addProcess方法代码示例

本文整理汇总了PHP中swoole_server::addProcess方法的典型用法代码示例。如果您正苦于以下问题:PHP swoole_server::addProcess方法的具体用法?PHP swoole_server::addProcess怎么用?PHP swoole_server::addProcess使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在swoole_server的用法示例。


在下文中一共展示了swoole_server::addProcess方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: function

    echo "#{$server->worker_id} message from #{$src_worker_id}: {$data}\n";
});
$server->on('task', function ($server, $task_id, $from_id, $data) {
    var_dump($task_id, $from_id, $data);
});
$server->on('finish', function ($server, $fd, $from_id) {
});
$server->on('receive', function (swoole_server $server, $fd, $from_id, $data) {
    if (trim($data) == 'task') {
        $server->task("async task coming");
    } else {
        $worker_id = 1 - $server->worker_id;
        $server->sendMessage("hello task process", $worker_id);
    }
});
$server->start();
$server = new swoole_server('127.0.0.1', 9501);
$process = new swoole_process(function ($process) use($server) {
    while (true) {
        $msg = $process->read();
        foreach ($server->connections as $conn) {
            $server->send($conn, $msg);
        }
    }
});
$server->addProcess($process);
$server->on('receive', function ($serv, $fd, $from_id, $data) use($process) {
    //群发收到的消息
    $process->write($data);
});
$server->start();
开发者ID:xiangdong1987,项目名称:AllInOne,代码行数:31,代码来源:test.php

示例2: switch

    switch ($cmd) {
        case 'fetch':
            $crawler_server->task($data, 0);
            $crawler_server->send($fd, "OK\n");
            break;
        default:
            echo "error cmd \n";
    }
});
$crawler_server->on('task', function (swoole_server $crawler_server, $task_id, $from_id, $data) {
    echo 'task start time--' . date('Y-m-d H:i:s') . "\n";
    echo 'tast_id :' . $task_id . "\n";
    echo 'client--from_id:' . $from_id . "\n";
    $driver = isset($data['driver']) ? $data['driver'] : '';
    $method = isset($data['method']) ? $data['method'] : 'fetch';
    $object = isset($data['object']) ? unserialize($data['object']) : '';
    $class = isset($data['class']) ? $data['class'] : 'Crawl';
    if (!$class && !$object || !$method) {
        $crawler_server->finish("error callback\n");
    }
    if ($object) {
        call_user_func_array(array($object, $method), array($data['data'], array('driver' => $driver)));
    } else {
        call_user_func_array("{$class}::{$method}", array($data['data'], array('driver' => $driver)));
    }
    $crawler_server->finish("OK\n");
});
//添加监控进程
$crawler_server->addProcess($crawler_monitor);
//server开始
$crawler_server->start();
开发者ID:imdaqian,项目名称:phpcrawler,代码行数:31,代码来源:crawler_server.php

示例3: switch

    switch ($cmd) {
        case 'fetch':
            $parser_server->task($data, 0);
            $parser_server->send($fd, "OK\n");
            break;
        default:
            echo "error cmd \n";
    }
});
$parser_server->on('task', function (swoole_server $parser_server, $task_id, $from_id, $data) {
    echo 'task start time--' . date('Y-m-d H:i:s') . "\n";
    echo 'tast_id :' . $task_id . "\n";
    echo 'client--from_id:' . $from_id . "\n";
    $driver = isset($data['driver']) ? $data['driver'] : '';
    $method = isset($data['method']) ? $data['method'] : 'fetch';
    $object = isset($data['object']) ? unserialize($data['object']) : '';
    $class = isset($data['class']) ? $data['class'] : 'Parse';
    if (!$class && !$object || !$method) {
        $crawler_server->finish("error callback\n");
    }
    if ($object) {
        call_user_func_array(array($object, $method), array($data['data'], array('driver' => $driver)));
    } else {
        call_user_func_array("{$class}::{$method}", array($data['data'], array('driver' => $driver)));
    }
    $parser_server->finish("OK\n");
});
//添加监控进程
$parser_server->addProcess($parser_monitor);
//server启动
$parser_server->start();
开发者ID:imdaqian,项目名称:phpcrawler,代码行数:31,代码来源:parser_server.php


注:本文中的swoole_server::addProcess方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。