Table of Contents
综述:
传送门:
声明:
普通终端启动:
守护进程模式启动:
DEMO:
客户端使用方法:
Telnet:
编写代码:
惊鸿一瞥:
示例:
Home Backend Development PHP Tutorial MeepoPS--轻量级 Socket 服务

MeepoPS--轻量级 Socket 服务

Jun 20, 2016 pm 12:26 PM

MeepoPS是Meepo PHP Socket的缩写。旨在提供高效稳定的由纯PHP开发的多进程SocketService。

MeepoPS可以轻松构建在线实时聊天,即时游戏,视频流媒体播放,RPC,实时监控,以及原本使用HTTP的接口/定时任务的场景中等。

综述:

  • 开发语言:PHP5.3以上

  • PHP作为最好的语言,不仅仅能依靠Nginx来开发Web应用,同时,也可以构建高效稳定的即时通讯类Socket应用

  • MeepoPS的最低运行要求是安装了PHP的PCNTL库

  • MeepoPS的定位是一个插件。不但可以独立运行,也可以依附与ThinkPHP,CodeIgniter,YII等MVC框架中

  • MeepoPS是多进程,高性能,高可用,高并发,分布式的轻量级Socket服务,安全稳定。代码维护在GitHub,开放源码,永久免费。

  • MeepoPS由纯PHP构建,代码简洁优雅。最好的语言,做更多的事情!

  • 没有复杂的代码和新生语法,原生PHP语言直接调用即可。

传送门:

  • 手册地址: http://meepops.lanecn.com

  • Github: https://github.com/lixuancn/MeepoPS

  • Bug提交: https://github.com/lixuancn/MeepoPS/issues

  • 微博: http://weibo.com/lanephp

MeepoPS官网

即时通讯

声明:

  • 绝大多数的PHP应用都部署在Linux服务器, 因此MeepoPS不支持非Unix操作系统(例如Windows)。 你可以使用Apple Mac(OS X), CentOS, Ubuntu, Red Hat, Fedora, FreeBSD等类Unix操作系统来启动MeepoPS。

  • Windows用户可以安装VirtualBox, Vmware等虚拟机软件来运行MeepoPS。

  • 多进程及信号处理需要依赖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/meepo_ps/meepo_ps_master.pid`".
Copy after login

守护进程模式启动:

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/meepo_ps/meepo_ps_master.pid`".
Copy after login

DEMO:

1. 基于Telnet协议的服务端使用方法请参考demo-telnet.php.2. 如果服务端启动的是HOST是0.0.0.0, 那么客户端可以是外机,可以是本机.本机可以是127.0.0.1, 也可以是localhost.3. 如果服务端启动的是HOST是127.0.0.1/localhost, 那么客户端是不能外机,只能是本机.
Copy after login

客户端使用方法:

Telnet:

客户端可使用telnet客户端.如: telnet 127.0.0.1 19910
Copy after login

编写代码:

客户端可借助编程语言的Socket来实现. 可参考Test/test_client.php
Copy after login

惊鸿一瞥:

  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目录下是示例案例,每一个目录是一个独立的项目,会不断添加。

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Explain JSON Web Tokens (JWT) and their use case in PHP APIs. Explain JSON Web Tokens (JWT) and their use case in PHP APIs. Apr 05, 2025 am 12:04 AM

JWT is an open standard based on JSON, used to securely transmit information between parties, mainly for identity authentication and information exchange. 1. JWT consists of three parts: Header, Payload and Signature. 2. The working principle of JWT includes three steps: generating JWT, verifying JWT and parsing Payload. 3. When using JWT for authentication in PHP, JWT can be generated and verified, and user role and permission information can be included in advanced usage. 4. Common errors include signature verification failure, token expiration, and payload oversized. Debugging skills include using debugging tools and logging. 5. Performance optimization and best practices include using appropriate signature algorithms, setting validity periods reasonably,

Describe the SOLID principles and how they apply to PHP development. Describe the SOLID principles and how they apply to PHP development. Apr 03, 2025 am 12:04 AM

The application of SOLID principle in PHP development includes: 1. Single responsibility principle (SRP): Each class is responsible for only one function. 2. Open and close principle (OCP): Changes are achieved through extension rather than modification. 3. Lisch's Substitution Principle (LSP): Subclasses can replace base classes without affecting program accuracy. 4. Interface isolation principle (ISP): Use fine-grained interfaces to avoid dependencies and unused methods. 5. Dependency inversion principle (DIP): High and low-level modules rely on abstraction and are implemented through dependency injection.

How to automatically set permissions of unixsocket after system restart? How to automatically set permissions of unixsocket after system restart? Mar 31, 2025 pm 11:54 PM

How to automatically set the permissions of unixsocket after the system restarts. Every time the system restarts, we need to execute the following command to modify the permissions of unixsocket: sudo...

Explain the concept of late static binding in PHP. Explain the concept of late static binding in PHP. Mar 21, 2025 pm 01:33 PM

Article discusses late static binding (LSB) in PHP, introduced in PHP 5.3, allowing runtime resolution of static method calls for more flexible inheritance.Main issue: LSB vs. traditional polymorphism; LSB's practical applications and potential perfo

How to debug CLI mode in PHPStorm? How to debug CLI mode in PHPStorm? Apr 01, 2025 pm 02:57 PM

How to debug CLI mode in PHPStorm? When developing with PHPStorm, sometimes we need to debug PHP in command line interface (CLI) mode...

How to send a POST request containing JSON data using PHP's cURL library? How to send a POST request containing JSON data using PHP's cURL library? Apr 01, 2025 pm 03:12 PM

Sending JSON data using PHP's cURL library In PHP development, it is often necessary to interact with external APIs. One of the common ways is to use cURL library to send POST�...

Explain late static binding in PHP (static::). Explain late static binding in PHP (static::). Apr 03, 2025 am 12:04 AM

Static binding (static::) implements late static binding (LSB) in PHP, allowing calling classes to be referenced in static contexts rather than defining classes. 1) The parsing process is performed at runtime, 2) Look up the call class in the inheritance relationship, 3) It may bring performance overhead.

See all articles