Giter Site home page Giter Site logo

epserver's Introduction

服务开发框架 epserver V1.1

你所要关心只有业务逻辑

  • 事件驱动
  • 多进程逻辑
  • 配置驱动

依赖扩展

  • PHP 5.5
  • swoole
  • pcntl --enable-pcntl
  • libev
  • System IPC --enable-sysvmsg --enable-sysvsem --enable-sysvshm

Example

多进程服务 demo

define('SERVER_PATH', __DIR__ . '/');
$loader = include SERVER_PATH . '../autoload.php';

use EPS\Bootstrap\MultiProcessServer;

$server = [
    'driver' => 'EPS\\Net\\ServerDriver\\Swoole',
    'host' => '0.0.0.0',
    'port' => 5501,
    'type' => 'TCP',
    'setting' => [
        'worker_num' => 3,
        'task_worker_num' => 3
    ]
];

$dispatcher = [
    'dispatcher' => 'EPS\\ServerDispatcher\\MessageDispatcher',
    'acceptMessage' => [
        'driver'  => 'EPS\\Driver\\Message\\SystemIPC',
        'message' => 'Accept5501',
        'option'  => [
            'perms' => 0666,
            'reset' => true
        ]
    ],
    'sendMessage' => [
        'driver'  => 'EPS\\Driver\\Message\\SystemIPC',
        'message' => 'Send5501',
        'option'  => [
            'perms' => 0666,
            'reset' => true
        ]
    ],
    'receiveMessage' => [
        'driver'  => 'EPS\\Driver\\Message\\SystemIPC',
        'message' => 'Receive5501',
        'option'  => [
            'perms' => 0666,
            'reset' => true
        ]
    ],
];

$logic = [
    'dispatchLogic' => 'Server\\Logic\\DispatchLogic',
    'workerNum' => 3
];
//MultiProcessServer::instance 第二个参数为 开启守护
MultiProcessServer::instance('ep_multi_process_server')
    ->setServerOption($server)
    ->setServerDispatcherOption($dispatcher)
    ->setLogicOption($logic)
    ->run();

分发逻辑 demo

/**
 * 简单服务开发框架>>EPS
 * (c) Evenlaz <[email protected]>
 */

namespace Server\Logic;

use EPS\ServerDispatcher\AbstractDispatchLogic;

class DispatchLogic extends AbstractDispatchLogic
{
    public function onAccept($sid, $connection) {
        echo sprintf("accept[%s]>>%s[%d]\n", $sid, $connection->ip, $connection->port);
        $this->send($sid, 'hello ' . $sid . "\n");
        $this->boardcast($sid . ' join room ~' . "\n");
    }
    public function onReceive($sid, $data) {
        $data = str_replace(["\n", "\r"], '', $data);
        if ($data == 'close') {
            $this->boardcast($sid . ' logout' . "\n");
            $this->close($sid);
        } else {
            $this->send($sid, 'you say ' . $data . "\n");
        }
        echo sprintf("receive[%s]>>%s\n", $sid, $data);
    }
    public function onClose($sid, $connection) {
        echo sprintf("close[%s]>>%s[%d]\n", $sid, $connection->ip, $connection->port);
    }
}

Document

License

Apache License Version 2.0 http://www.apache.org/licenses/LICENSE-2.0.html

epserver's People

Contributors

wendywangj avatar

Watchers

Mark.Wang avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.