PHPackages                             pengyu/server - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [HTTP &amp; Networking](/categories/http)
4. /
5. pengyu/server

ActiveLibrary[HTTP &amp; Networking](/categories/http)

pengyu/server
=============

a compact network communication server wirtten by php

04PHP

Since Sep 2Pushed 6y agoCompare

[ Source](https://github.com/herepy/PyServer)[ Packagist](https://packagist.org/packages/pengyu/server)[ RSS](/packages/pengyu-server/feed)WikiDiscussions master Synced 2w ago

READMEChangelogDependenciesVersions (1)Used By (0)

PyServer
========

[](#pyserver)

**PyServer是一款纯PHP编写的网络通信框架，架构简单易上手**

简介
--

[](#简介)

传统PHP编写的Web应用所使用的架构一般是LNMP模式，Nginx+PHP-FPM的经典搭配可以帮助开发者快速搭建一套Web服务器用于自身的业务。随着业务的发展，功能需求也变得多样性，单一“请求-回复”的响应模式变得不够用，比如一些长连接的业务使用原先的架构实现就会变得非除困难。虽然有Swoole的出现，但是上手门槛对于习惯了CURD一把梭的PHPer来说有点高，有一定的学习成本。PyServer其实就是一个缩水版的Workerman，在代码和功能缩减的情况下保证业务的完整性，框架默认实现了HTTP协议，使得开发者可以脱离Nginx当作独立的Server，自定义协议可方便的适应业务需求。

功能特色
----

[](#功能特色)

- 架构简单(Master-Worker模型)
- composer快速安装引入项目
- 守护进程模式
- 工作进程数可调整
- 毫秒级定时器
- 多种调度器供选择(在安装了event扩展时，默认是Event调度器)
- Tcp长连接
- 协议可自定义
- 可作为Http服务器
- 可作为WebSocket服务器

安装
--

[](#安装)

##### git方式安装

[](#git方式安装)

```
git clone https://github.com/herepy/PyServer.git
cd PyServer && composer install
```

##### composer方式安装

[](#composer方式安装)

```
composer require pengyu/server
```

示例
--

[](#示例)

##### 配置

[](#配置)

```
require_once "vendor/autoload.php";

use Pengyu\Server\Worker\Server;

$worker=new Server("http://0.0.0.0:8080");

$worker->config([
    "workerCount"   =>  4,                //工作进程数
    "deamon"        =>  true              //守护进程模式
    "logFile"       =>  "/log/xx.log"     //日志文件地址
    "accessFile"    =>  "/log/access.log" //http访问记录文件地址
]);

//设置工作进程启动时的回调
$worker->on('workerStart',function ($worker){
    //do something
});

$worker->run();
```

##### Http

[](#http)

```
require_once "vendor/autoload.php";

use Pengyu\Server\Worker\Server;

$worker=new Server("http://0.0.0.0:8080");

//设置接收到客户端请求时的回调
$worker->on('request',function ($content,$response){
    var_dump($content);
    //相关设置
    $response->status(200);
    $response->header("Content-Type","text/html;charset=utf-8");
    $response->cookie("name","py",3600);
    //响应数据
    $response->end("hello world");
});

$worker->run();
```

##### Websocket

[](#websocket)

```
require_once "vendor/autoload.php";

use Pengyu\Server\Worker\Server;

$worker=new PyServer("ws://0.0.0.0:8888");

$worker->on('message',function ($connection,$fd,$content){
    //发送数据
    $connection->send($fd,"received:".$content);
});

$worker->run();
```

##### 定时器

[](#定时器)

```
require_once "vendor/autoload.php";

use Pengyu\Server\Worker\Server;
use Pengyu\Server\Util\Timer;

$worker=new PyServer("http://0.0.0.0:8080");

$worker->on('workerStart',function (){
    //持续性定时器
    $timerA=new Timer(2,function(){
        echo "persist timer";
    },true);
    //一次性定时器
    $timerB=new Timer(5,function()use($timerA){
        echo "once timer";
        //取消定时器
        $timerA->cancel();
    });
});

$worker->run();
```

###  Health Score

18

—

LowBetter than 8% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity3

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity36

Early-stage or recently created project

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/1018252?v=4)[Pengyu](/maintainers/Pengyu)[@pengyu](https://github.com/pengyu)

---

Top Contributors

[![herepy](https://avatars.githubusercontent.com/u/16030800?v=4)](https://github.com/herepy "herepy (223 commits)")

### Embed Badge

![Health badge](/badges/pengyu-server/health.svg)

```
[![Health](https://phpackages.com/badges/pengyu-server/health.svg)](https://phpackages.com/packages/pengyu-server)
```

###  Alternatives

[php-http/cache-plugin

PSR-6 Cache plugin for HTTPlug

25025.5M80](/packages/php-http-cache-plugin)[illuminate/http

The Illuminate Http package.

11937.2M6.6k](/packages/illuminate-http)[rdkafka/rdkafka

A PHP extension for Kafka

2.2k20.0k1](/packages/rdkafka-rdkafka)[httpsoft/http-message

Strict and fast implementation of PSR-7 and PSR-17

87930.4k113](/packages/httpsoft-http-message)[mezzio/mezzio-router

Router subcomponent for Mezzio

265.3M84](/packages/mezzio-mezzio-router)[serpapi/google-search-results-php

Get Google, Bing, Baidu, Ebay, Yahoo, Yandex, Home depot, Naver, Apple, Duckduckgo, Youtube search results via SerpApi.com

69122.6k](/packages/serpapi-google-search-results-php)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
