MeepoPS是Meepo PHP Socket的缩写,旨在提供稳定的Socket服务。可以轻松构建在线实时聊天、即时游戏、视频流媒体播放等。

Related tags

Frameworks MeepoPS
Overview

MeepoPS

MeepoPS是Meepo PHP Socket的缩写. 旨在提供高效稳定的由纯PHP开发的多进程SocketService.
MeepoPS可以轻松构建在线实时聊天, 即时游戏, 视频流媒体播放, RPC, 实时监控, 以及原本使用HTTP的接口/定时任务的场景中等.

综述:

  • 目前版本为V1.0.0 ( 查看改动日志 ).
  • PHP作为最好的语言, 不仅仅能依靠Nginx来开发Web应用, 同时,也可以构建高效稳定的即时通讯类Socket应用.
  • MeepoPS的最低运行要求是安装了PHP的PCNTL库.
  • MeepoPS的定位是一个插件. 不但可以独立运行, 也可以依附与ThinkPHP, CodeIgniter, YII等MVC框架中.

传送门:

声明:

  • 绝大多数的PHP应用都部署在Linux服务器, 因此MeepoPS不支持非Unix操作系统(例如Windows). 你可以使用Apple Mac(OS X), CentOS, Ubuntu, Red Hat, Fedora, FreeBSD等类Unix操作系统来启动MeepoPS.
  • Windows用户可以安装VirtualBox, Vmware等虚拟机软件来运行MeepoPS.
  • MeepoPS需要PHP的POSIX库. POSIX是PHP默认安装的, 通常情况下你不需要手动安装. 如何安装: PHP手册-POSIX安装
  • 多进程及信号处理需要依赖PHP的PCNTL库. MeepoPS深度依赖PCNTL, 因此PCNTL库是必须安装的, 即使只启动一个进程的MeepoPS, 仍然需要安装PCNTL. 如何安装: PHP手册-PCNTL安装
  • 在大规模访问下, 我们建议安装PHP的PECL扩展Libevent, 但这不是必须的. 在高链接数的场景下, Libevent表现优异. 如何安装: PHP手册-Libevent安装. 截止2016-05-06, PHP官方的Libevent扩展不支持PHP7, PHP7下的Libevent安装方法: PHP7的Libevent分支
  • 默认监听链接的方式为Select轮询机制. PHP的Select轮询机制最多只能监听1024个链接. 想要突破这个限制, 要么安装Libevent, 要么使用--enable-fd-setsize=2048重新编译安装PHP.

快速入门:

服务端使用方法:

基础功能和用法都写在demo-telnet.php, 基本您就可以直接用.

普通终端启动:
1. 启动: 命令行输入"php demo-telnet.php start".
2. 状态: 命令行输入"php demo-telnet.php status".
3. 平滑结束: 启动后按下"ctrl + c"即可.
4. 强行结束: 命令行输入"kill -INT `cat /var/run/meepops/meepops_master.pid`".
守护进程模式启动:
1. 启动: 命令行输入"php demo-telnet.php start -d".
2. 状态: 命令行输入"php demo-telnet.php status".
3. 平滑结束: 命令行输入"php demo-telnet.php stop".
4. 强行结束: 命令行输入"php demo-telnet.php kill".
5. 强行结束: 命令行输入"kill -INT `cat /var/run/meepops/meepops_master.pid`".
DEMO:
1. 基于Telnet协议的服务端使用方法请参考demo-telnet.php.
2. 如果服务端启动的是HOST是0.0.0.0, 那么客户端可以是外机,可以是本机.本机可以是127.0.0.1, 也可以是localhost.
3. 如果服务端启动的是HOST是127.0.0.1/localhost, 那么客户端是不能外机,只能是本机.
客户端使用方法:
Telnet:
客户端可使用telnet客户端.如: telnet 127.0.0.1 19910
编写代码:
客户端可借助编程语言的Socket来实现. 可参考Test/test_client.php
惊鸿一瞥:
  1. MeepoPS/config.ini是MeepoPS的配置文件. 采用和php.ini同样的格式, ";"为注释.
  2. 必须引入MeepoPS/index.php文件. 使用MeepoPS都是从 require_once 'MeepoPS/index.php' 开始的.
  3. MeepoPS/Api/目录下的文件为暴露给用户的接口. 需要实例化接口类文件, MeepoPS的使用都是围绕实例化接口文件后的对象来操作的. 实例化的时候传入监听的HOST和端口即可.
  4. MeepoPS会以回调函数的方式来触发您设置的业务逻辑. 比如新链接加入时会回调您设置的"Hello world", 再比如某个链接发送了消息"PING"时, 会回调您设置的返回消息"PONG".
  5. MeepoPS可以启动多个实例, 每一次的new接口类文件都是一次实例化.
  6. MeepoPS不但可以实例化多个接口类文件, 也可以实例化同一个接口类文件多次. 比如启动了三个实例, 分别监听了19910, 19911, 19912端口.
  7. 实例化接口类文件并进行了相关设置后, 调用\MeepoPS\runMeepoPS()即可启动MeepoPS.
  8. \MeepoPS\runMeepoPS()之后的所有代码都将不会执行.

示例:

Example目录下是示例案例, 每一个目录是一个独立的项目. 会不断添加.

测试案例:

请看文档-测试一栏

Comments
  • PHP Version: 7.1.4  下 Tcp.php ( 353行)的 unset($this)

    PHP Version: 7.1.4 下 Tcp.php ( 353行)的 unset($this)

    MeepoPS Start: [OK] -------------------------- MeepoPS Start Success ------------------------ MeepoPS Version: 0.0.5 | PHP Version: 7.1.4 | Master Pid: 78621 | Event: Select -------------------------- Instances List -------------------------

    Fatal error: Cannot unset $this in MeepoPS/MeepoPS/Core/TransportProtocol/Tcp.php on line 353

    这个可以删除 Tcp.php ( 353行)的 unset($this) 就可以了。

    ---- 弱弱问一下 这个库还在维护么?

    opened by iMactool 9
  • websocket和HTTP的API接口全部报错,

    websocket和HTTP的API接口全部报错,

    [root@VM_40_223_centos meepops]# sudo php demo-websocket.php start

    Warning: Unexpected character in input: '' (ASCII=92) state=1 in /www/wwwroot/meepops/demo-websocket.php on line 16

    Warning: Unexpected character in input: '' (ASCII=92) state=1 in /www/wwwroot/meepops/demo-websocket.php on line 16

    Parse error: syntax error, unexpected T_STRING in /www/wwwroot/meepops/demo-websocket.php on line 16 [root@VM_40_223_centos meepops]# sudo php demo-http.php start

    Warning: Unexpected character in input: '' (ASCII=92) state=1 in /www/wwwroot/meepops/demo-http.php on line 17

    Warning: Unexpected character in input: '' (ASCII=92) state=1 in /www/wwwroot/meepops/demo-http.php on line 17

    Parse error: syntax error, unexpected T_STRING in /www/wwwroot/meepops/demo-http.php on line 17

    opened by LiHaoLi 6
  • PHP Fatal error:  Uncaught Error: Call to undefined function ssh2_connect()

    PHP Fatal error: Uncaught Error: Call to undefined function ssh2_connect()

    你好!

    当浏览器输入http://127.0.0.1:19911/ 访问的时候服务端报错,

    $ sudo php real_time_monitor_ssh_server.php restart
    [INFO][2017-04-29 23:24:45][74344]MeepoPS receives the "restart" instruction, MeepoPS will graceful restart
    MeepoPS Stop:                          [OK]
    MeepoPS Start:                         [OK]
    -------------------------- MeepoPS Start Success ------------------------
    MeepoPS Version: 0.0.5 | PHP Version: 7.0.15-0ubuntu0.16.04.4 | Master Pid: 74344 | Event: Select
    -------------------------- Instances List -------------------------
    MeepoPS-WebSocket  websocket://0.0.0.0:19910  Child Process: 1
    MeepoPS-Http  http://0.0.0.0:19911  Child Process: 1
    
    PHP Fatal error:  Uncaught Error: Call to undefined function ssh2_connect() in /home/tinywan/MeepoPS/Example/Real_Time_Monitor_Ssh/websocket_server.php:58
    Stack trace:
    #0 /home/tinywan/MeepoPS/Example/Real_Time_Monitor_Ssh/websocket_server.php(40): _connectServer(Object(MeepoPS\Core\TransportProtocol\Tcp), '127.0.0.1', 'root', '123456')
    #1 /home/tinywan/MeepoPS/Example/Real_Time_Monitor_Ssh/websocket_server.php(29): memfree(Object(MeepoPS\Core\TransportProtocol\Tcp), Array)
    

    浏览器没有数据:

    qq 20170429232919

    opened by Tinywan 4
  • PHP 7.1.8RC1 运行sudo php demo-telnet.php start 报错

    PHP 7.1.8RC1 运行sudo php demo-telnet.php start 报错

    环境介绍    linux版本:CentOS release 6.9    php:PHP 7.1.8RC1   MeepoPS:最新的,截止到发问前

    问题   运行 sudo php demo-telnet.php start 报错,如下

    [INFO][2017-09-05 17:45:12][15356]MeepoPS check shutdown reason
    [ERROR][2017-09-05 17:45:12][15356]stream_socket_serverMeepoPS unexpectedly quits. last error: {"type":64,"message":"Redefinition of parameter $_null","file":"\/home\/zuosongyan\/web\/MeepoPS\/MeepoPS\/Core\/Event\/Libevent.php","line":155}
    ^C[INFO][2017-09-05 17:45:12][14024]MeepoPS is stopping...
    [ERROR][2017-09-05 17:45:12][14024]MeepoPS instance(MeepoPS-Telnet:15356) exit. Status: 65280
    [INFO][2017-09-05 17:45:12][14024]MeepoPS has been pulled out
    
    opened by zsyprince 2
  • 关于 Libevent和Select 自动选择问题(PHP多版本环境引起)【已解决】

    关于 Libevent和Select 自动选择问题(PHP多版本环境引起)【已解决】

    起因是我发现我明明安装了 Libevent ,但是 启动MeepoPS的时候却没有,发现cli下的php是系统自带的(我用vagrant+box)

    接着看手册里的配置信息默认配置是 Select 轮询机制. [event] 这个节段里配置的,但是没有配置 Libevent 再看源码的时候发现了:MeepoPS 自动选择优先会使用 Libevent

    那么问题就简单了,比如我的环境下 系统自带的php在 /usr/bin/php 下,安装的在 /usr/local/php56/bin/php

    解决方案 三步骤走起

    sudo cp /usr/bin/php /usr/bin/php55
    sudo rm /usr/bin/php
    sudo ln -s /usr/local/php56/bin/php /usr/bin/php
    
    

    再启动MeepoPS 就可以看到Event: Libevent

    MeepoPS Start:                         [OK]
    -------------------------- MeepoPS Start Success ------------------------
    MeepoPS Version: 0.0.5 | PHP Version: 5.6.29 | Master Pid: 14450 | Event: Libevent
    

    这点官方文档个人觉得应该加个 notice 吧 ,由于没有就当是一个新的Issues吧 :)

    opened by iMactool 2
  • MeepoPS already running. file: real_time_monitor_ssh_server.php

    MeepoPS already running. file: real_time_monitor_ssh_server.php

    启动 提示一下信息

    tinywan@tinywan:~/MeepoPS/Example/Real_Time_Monitor_Ssh$ sudo php real_time_monitor_ssh_server.php start
    [sudo] tinywan 的密码: 
    [FATAL][2017-04-28 12:54:20][36007]MeepoPS already running. file: real_time_monitor_ssh_server.php
    
    opened by Tinywan 2
  • 基于WebSocket的实时监控报错,无法访问到localhost:19910

    基于WebSocket的实时监控报错,无法访问到localhost:19910

    PHP Fatal error: Can't use function return value in write context in /var/www/imooc/socket/MeepoPS/MeepoPS/Library/Session.php on line 32 [INFO][2017-12-10 20:11:57][22084]MeepoPS check shutdown reason [ERROR][2017-12-10 20:11:57][22084]stream_socket_serverMeepoPS unexpectedly quits. last error: {"type":64,"message":"Can't use function return value in write context","file":"/var/www/imooc/socket/MeepoPS/MeepoPS/Library/Session.php","line":32} [ERROR][2017-12-10 20:11:57][22079]MeepoPS instance(MeepoPS-Http:22084) exit. Status: 65280

    opened by sunyinggang 1
Owner
Lane
我的repository中,有很多不是正儿八经的项目、废代码、书上的例子,是因为老师从小就教育我们,好记星不如烂笔头,光看不行,得写。谁让我笨呢。
Lane
FuelPHP v1.x is a simple, flexible, community driven PHP 5.3+ framework, based on the best ideas of other frameworks, with a fresh start! FuelPHP is fully PHP 7 compatible.

FuelPHP Version: 1.8.2 Website Release Documentation Release API browser Development branch Documentation Development branch API browser Support Forum

Fuel 1.5k Dec 28, 2022
An asynchronous event driven PHP socket framework. Supports HTTP, Websocket, SSL and other custom protocols. PHP>=5.3.

Workerman What is it Workerman is an asynchronous event-driven PHP framework with high performance to build fast and scalable network applications. Wo

walkor 10.2k Dec 31, 2022
A multithreaded application server for PHP, written in PHP.

appserver.io, a PHP application server This is the main repository for the appserver.io project. What is appserver.io appserver.io is a multithreaded

appserver.io 951 Dec 25, 2022
Fast php framework written in c, built in php extension

Yaf - Yet Another Framework PHP framework written in c and built as a PHP extension. Requirement PHP 7.0+ (master branch)) PHP 5.2+ (php5 branch) Inst

Xinchen Hui 4.5k Dec 28, 2022
💫 Vega is a CLI mode HTTP web framework written in PHP support Swoole, WorkerMan / Vega 是一个用 PHP 编写的 CLI 模式 HTTP 网络框架,支持 Swoole、WorkerMan

Mix Vega 中文 | English Vega is a CLI mode HTTP web framework written in PHP support Swoole, WorkerMan Vega 是一个用 PHP 编写的 CLI 模式 HTTP 网络框架,支持 Swoole、Work

Mix PHP 46 Apr 28, 2022
Hello, this is simple attribute validation for PHP Models, based on the new features, presented in PHP 8

Hello, this is simple attribute validation for PHP Models, based on the new features, presented in PHP 8 It works as a standalone and can be use in custom projects or in libraries like Symfony and Laravel.

Ivan Grigorov 88 Dec 30, 2022
A PHP framework for web artisans.

About Laravel Laravel is a web application framework with expressive, elegant syntax. We believe development must be an enjoyable and creative experie

The Laravel Framework 72k Jan 7, 2023
The Symfony PHP framework

Symfony is a PHP framework for web and console applications and a set of reusable PHP components. Symfony is used by thousands of web applications (in

Symfony 27.8k Jan 2, 2023
Open Source PHP Framework (originally from EllisLab)

What is CodeIgniter CodeIgniter is an Application Development Framework - a toolkit - for people who build web sites using PHP. Its goal is to enable

B.C. Institute of Technology 18.2k Dec 29, 2022
🚀 Coroutine-based concurrency library for PHP

English | 中文 Swoole is an event-driven asynchronous & coroutine-based concurrency networking communication engine with high performance written in C++

Swoole Project 17.7k Jan 8, 2023
Yii 2: The Fast, Secure and Professional PHP Framework

Yii 2 is a modern framework designed to be a solid foundation for your PHP application. It is fast, secure and efficient and works right out of the bo

Yii Software 14k Dec 31, 2022
CakePHP: The Rapid Development Framework for PHP - Official Repository

CakePHP is a rapid development framework for PHP which uses commonly known design patterns like Associative Data Mapping, Front Controller, and MVC. O

CakePHP 8.6k Dec 31, 2022
Slim is a PHP micro framework that helps you quickly write simple yet powerful web applications and APIs.

Slim Framework Slim is a PHP micro-framework that helps you quickly write simple yet powerful web applications and APIs. Installation It's recommended

Slim Framework 11.5k Jan 4, 2023
High performance, full-stack PHP framework delivered as a C extension.

Phalcon Framework Phalcon is an open source web framework delivered as a C extension for the PHP language providing high performance and lower resourc

The Phalcon PHP Framework 10.7k Jan 8, 2023
🚀 PHP Microservice Full Coroutine Framework

PHP microservice coroutine framework 中文说明 Introduction Swoft is a PHP microservices coroutine framework based on the Swoole extension. Like Go, Swoft

Swoft Cloud 5.5k Dec 28, 2022
Open Source PHP Framework (originally from EllisLab)

CodeIgniter 4 Development What is CodeIgniter? CodeIgniter is a PHP full-stack web framework that is light, fast, flexible and secure. More informatio

CodeIgniter 4 web framework 4.5k Jan 2, 2023
Asynchronous & Fault-tolerant PHP Framework for Distributed Applications.

Kraken PHP Framework ~ Release the Kraken! Note: This repository contains the core of the Kraken Framework. If you want to start developing new applic

Kraken 1.1k Dec 27, 2022
High-Performance Long-Living PHP Framework for modern enterprise application development

Documentation · Discord · Telegram · Twitter Spiral Framework is a High-Performance Long-Living Full-Stack framework and group of over sixty PSR-compa

Spiral Scout 1.4k Jan 1, 2023
A simple, secure, and scalable PHP application framework

Opulence Introduction Opulence is a PHP web application framework that simplifies the difficult parts of creating and maintaining a secure, scalable w

Opulence 732 Dec 30, 2022