• Stars
    star
    251
  • Rank 161,862 (Top 4 %)
  • Language
    PHP
  • License
    MIT License
  • Created almost 11 years ago
  • Updated over 2 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

workerman作为进程管理器,json作为协议的远程服务调用的框架

workerman

workerman 是一个高性能的PHP socket服务框架,开发者可以在这个框架下开发各种网络应用,例如Rpc服务、聊天室、游戏等。 workerman 具有以下特性

  • 多进程
  • 支持TCP/UDP
  • 支持各种应用层协议
  • 使用libevent事件轮询库,支持高并发
  • 支持文件更新检测及自动加载
  • 支持服务平滑重启
  • 支持telnet远程控制及监控
  • 支持异常监控及告警
  • 支持长连接
  • 支持以指定用户运行worker进程

所需环境

workerman需要PHP版本不低于5.3,只需要安装PHP的Cli即可,无需安装PHP-FPM、nginx、apache

workerman不能运行在Window平台

安装

1、下载 或者 git clone https://github.com/walkor/workerman-JsonRpc

2、运行 composer install

启动停止

启动
php start.php start -d

重启启动
php start.php restart

平滑重启/重新加载配置
php start.php reload

查看服务状态
php start.php status

停止
php start.php stop

Rpc应用使用方法

客户端同步调用:

<?php
include_once 'yourClientDir/RpcClient.php';

$address_array = array(
          'tcp://127.0.0.1:2015',
          'tcp://127.0.0.1:2015'
          );
// 配置服务端列表
RpcClient::config($address_array);

$uid = 567;

// User对应applications/JsonRpc/Services/User.php 中的User类
$user_client = RpcClient::instance('User');

// getInfoByUid对应User类中的getInfoByUid方法
$ret_sync = $user_client->getInfoByUid($uid);

客户端异步调用:

RpcClient支持异步远程调用

<?php
include_once 'yourClientDir/RpcClient.php';
// 服务端列表
$address_array = array(
  'tcp://127.0.0.1:2015',
  'tcp://127.0.0.1:2015'
  );
// 配置服务端列表
RpcClient::config($address_array);

$uid = 567;
$user_client = RpcClient::instance('User');

// 异步调用User::getInfoByUid方法
$user_client->asend_getInfoByUid($uid);
// 异步调用User::getEmail方法
$user_client->asend_getEmail($uid);

这里是其它的业务代码
....................
....................

// 需要数据的时候异步接收数据
$ret_async1 = $user_client->arecv_getEmail($uid);
$ret_async2 = $user_client->arecv_getInfoByUid($uid);

这里是其他业务逻辑

服务端:

服务端每个类提供一组服务,类文件默认放在Applications/JsonRpc/Services目录下。
客户端实际上是远程调用这些类的静态方法。 例如:

<?php
RpcClient::instance('User')->getInfoByUid($uid);

调用的是Applications/JsonRpc/Services/User.php 中 User类的getInfoByUid方法。
User.php文件类似这样

<?php
class User
{
       public static function getInfoByUid($uid)
        {
            // ....
        }
   
        public static function getEmail($uid)
        {
            // ...
        }
}

如果你想要增加一组服务,可以在这个目录下增加类文件即可。

rpc监控页面

rpc监控页面地址 http://ip:55757

More Repositories

1

workerman

An asynchronous event driven PHP socket framework. Supports HTTP, Websocket, SSL and other custom protocols.
PHP
11,067
star
2

phpsocket.io

A server side alternative implementation of socket.io in PHP based on workerman.
PHP
2,284
star
3

webman

Probably the fastest PHP web framework in the world.
PHP
2,126
star
4

workerman-todpole

HTML5+WebSocket+PHP(Workerman) , rumpetroll server writen using php
PHP
1,844
star
5

workerman-chat

Websocket chat room written in PHP based on workerman.
PHP
1,185
star
6

GatewayWorker

Distributed realtime messaging framework based on workerman.
PHP
1,007
star
7

web-msg-sender

Web message pusher written in PHP based on workerman.
PHP
922
star
8

live-camera

Live camera based on HTML5+Canvas+Websocket+PHP (Workerman).
PHP
458
star
9

BrowserQuest-PHP

BrowserQuest server in PHP base on workerman. A PHP/HTML5/JavaScript multiplayer game experiment.
PHP
376
star
10

workerman-statistics

一个分布式统计监控系统 包含PHP客户端 、服务端
PHP
350
star
11

GatewayClient

Sdk For GatewayWorker
PHP
334
star
12

workerman-thrift

Thrift RPC for php based on workerman.
PHP
274
star
13

workerman-webrtc

php webrtc demo based on workerman
JavaScript
251
star
14

live-ascii-camera

利用HTML5将摄像头视频转换为ascii字符,通过websocket实时传输给其它页面。服务端使用workerman
PHP
215
star
15

php-socks5

socks5 proxy written in PHP based on workerman.
PHP
208
star
16

mqtt

Asynchronous MQTT client for PHP based on workerman.
PHP
203
star
17

php-http-proxy

HTTP proxy written in PHP based on workerman.
PHP
201
star
18

phptty

Share your terminal as a web application. PHP terminal emulator based on workerman.
PHP
173
star
19

workerman-vmstat

在浏览器里面显示以更友好的方式实时显示vmstats信息,包括内存、IO、cpu等信息
PHP
160
star
20

channel

Interprocess communication component for workerman
PHP
136
star
21

workerman-flappy-bird

flappy bird 多人在线版
PHP
119
star
22

webman-framework

webman-framework
PHP
116
star
23

workerman-for-win

workerman 3.x windows 版本(目前linux版本已经兼容windows,此版本不再维护)
PHP
109
star
24

workerman-queue

workerman 消息队列
PHP
107
star
25

GlobalData

进程间变量共享组件,用于分布式数据共享
PHP
73
star
26

workerman-todpole-web

小蝌蚪互动聊天室-适合虚拟空间使用(后端直接与workerman主机通讯。请保留页面上workerman的相关链接)
JavaScript
73
star
27

workerman-filemonitor

监控文件更新并自动reload workerman
PHP
67
star
28

workerman-manual

Workerman manual
PHP
65
star
29

crontab

A crontab written in PHP based on workerman
PHP
60
star
30

mysql

Long-living MySQL connection for daemon.
PHP
55
star
31

workerman-chat-for-win

workerman-chat windows版本
PHP
48
star
32

http-client

Asynchronous http client for PHP based on workerman.
PHP
47
star
33

rabbitmq

Asynchronous rabbitmq client for PHP based on workerman.
PHP
35
star
34

redis-queue

Message queue system written in PHP based on workerman and backed by Redis.
PHP
35
star
35

workerman-todpole-for-win

workerman-todpole-for-win
PHP
25
star
36

workerman.net

workerman.net主页源代码
PHP
25
star
37

phpsocket.io-emitter

PHP
23
star
38

workerman-MT

workerman多线程版本,同时支持Linux平台与Windows平台,接口与原Linux多进程版本兼容
PHP
22
star
39

redis

Asynchronous redis client for PHP based on workerman.
PHP
18
star
40

workerman-filemonitor-inotify

workerman文件监控并自动reload inotify版本
PHP
17
star
41

workerman-manual-zh

workerman中文手册
17
star
42

web-msg-sender-for-win

web-msg-sender for win
PHP
17
star
43

GatewayWorker-for-win

GatewayWorker for windows.
PHP
16
star
44

global-timer

Distributed timer for workerman.
PHP
15
star
45

phpsocket.io-for-win

PHP
12
star
46

webserver-example

PHP
10
star
47

stomp

Asynchronous Stomp client for PHP based on workerman.
PHP
8
star
48

tcp-proxy-demo

一个tcp代理服务器的demo
PHP
8
star
49

en.workerman.net

en.workerman.net
PHP
4
star
50

workerman-teach

PHP
4
star
51

gateway-doc

GatewayWorker manual
3
star