PHPackages                             wangjian/socket\_for\_linux - 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. [Framework](/categories/framework)
4. /
5. wangjian/socket\_for\_linux

ActiveLibrary[Framework](/categories/framework)

wangjian/socket\_for\_linux
===========================

PHP写的高并发服务器框架，支持websocket和http协议

27124PHP

Since Sep 30Pushed 8y ago3 watchersCompare

[ Source](https://github.com/wangsir0624/socket_for_linux)[ Packagist](https://packagist.org/packages/wangjian/socket_for_linux)[ RSS](/packages/wangjian-socket-for-linux/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependenciesVersions (1)Used By (0)

socket\_for\_linux
==================

[](#socket_for_linux)

一个用来快速搭建websocket和http服务器的框架，只需要几行代码就可以搭建一个服务器。使用多进程和IO复用来实现高并发；使用共享内存进行进程间的通信。支持守护进程，支持服务器的平滑重启。

Usage
-----

[](#usage)

### Http服务器的使用

[](#http服务器的使用)

进入到根目录中，运行php http.php start即可开启http服务

#### 特性

[](#特性)

###### 1、多进程+IO复用，高并发

[](#1多进程io复用高并发)

###### 2、HTTP长连接

[](#2http长连接)

###### 3、支持虚拟主机配置

[](#3支持虚拟主机配置)

###### 4、支持前台进程和守护进程两种方式运行，可以随时监控服务器运行状态，支持平滑重启

[](#4支持前台进程和守护进程两种方式运行可以随时监控服务器运行状态支持平滑重启)

###### 5、异步发送数据，在发送大文件时不会阻塞

[](#5异步发送数据在发送大文件时不会阻塞)

#### 服务器参数配置

[](#服务器参数配置)

除了使用网站根目录的http.php外，你也可以编写自己的入口文件，下面是服务器配置介绍

```
//初始化一个服务器
$server = new \Wangjian\Socket\HttpServer('115.29.198.111', 11111);

//配置worker进程数
$server->wokers = 4;

//服务器是否以守护进程方式运行
$server->deamon = false;

//连接的timeout值，默认为60秒
$server->timeout = 60;

//服务器配置
$server->hosts = array(
    'default' => [
        'root' => '/data/dmz/test/www',
        'index' => 'index.php index.html index.htm'
    ],

    'test.test.com' => [
        'root' => '/data/dmz/test/test',
        'index' => 'index.php index.html index.htm'
    ]
);

//运行
$server->runAll();
```

### Websocket服务器的使用

[](#websocket服务器的使用)

#### 服务器的运行

[](#服务器的运行)

进入到根目录中，运行php websocket.php start即可开启服务

#### 服务器参数配置

[](#服务器参数配置-1)

除了使用网站根目录的websocket.php外，你也可以编写自己的入口文件，下面是服务器配置介绍

```
require_once __DIR__.'/vendor/autoload.php';

//初始化一个服务器
$server = new \Wangjian\Socket\WebSocketServer('115.29.198.111', 11111);

//配置worker进程数
$server->wokers = 2;

//服务器是否以守护进程方式运行
$server->deamon = false;

//连接的timeout值，默认为60秒
$server->timeout = 3600;

//服务器接受客户端连接时调用的回调函数
$server->onConnection = function($connection) {
    $pid = posix_getpid();
    echo "process $pid accept the connection from the client ".$connection->getRemoteAddress()."\r\n";
};

//服务器接受接收客户端消息时触发的回调函数
$server->onMessage = function($connection, $message) {
    echo "message from client: $message\r\n";
    $connection->sendString($message);
};

//服务器连接出错时触发的回调函数
$server->onError = function() {};

//服务器连接关闭时触发的回调函数
$server->onClose = function() {};

//运行
$server->runAll();
```

服务器运行情况监视可以
-----------

[](#服务器运行情况监视可以)

可以通过调用php http.php status来查看服务器的运行情况

服务器关闭
-----

[](#服务器关闭)

可以通过调用php http.php stop来停止服务器

平滑重启
----

[](#平滑重启)

可以通过调用php http.php restart来平滑重启服务器

###  Health Score

24

—

LowBetter than 32% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity17

Limited adoption so far

Community13

Small or concentrated contributor base

Maturity41

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 96% 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://www.gravatar.com/avatar/804f387c38e2dfd45455daecf401d7b45804826d8d4d7a440e92c0f4df90246c?d=identicon)[wangsir0624](/maintainers/wangsir0624)

---

Top Contributors

[![wangsir0624](https://avatars.githubusercontent.com/u/19991740?v=4)](https://github.com/wangsir0624 "wangsir0624 (24 commits)")[![ahao008](https://avatars.githubusercontent.com/u/24367532?v=4)](https://github.com/ahao008 "ahao008 (1 commits)")

### Embed Badge

![Health badge](/badges/wangjian-socket-for-linux/health.svg)

```
[![Health](https://phpackages.com/badges/wangjian-socket-for-linux/health.svg)](https://phpackages.com/packages/wangjian-socket-for-linux)
```

###  Alternatives

[laravel/telescope

An elegant debug assistant for the Laravel framework.

5.2k67.8M190](/packages/laravel-telescope)[laravel/passport

Laravel Passport provides OAuth2 server support to Laravel.

3.4k85.0M529](/packages/laravel-passport)[spiral/roadrunner

RoadRunner: High-performance PHP application server and process manager written in Go and powered with plugins

8.4k12.2M84](/packages/spiral-roadrunner)[nolimits4web/swiper

Most modern mobile touch slider and framework with hardware accelerated transitions

41.8k177.2k1](/packages/nolimits4web-swiper)[laravel/dusk

Laravel Dusk provides simple end-to-end testing and browser automation.

1.9k36.7M255](/packages/laravel-dusk)[laravel/prompts

Add beautiful and user-friendly forms to your command-line applications.

708181.8M591](/packages/laravel-prompts)

PHPackages © 2026

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