PHP code example of zhanguangcheng / workerman-server

1. Go to this page and download the library: Download zhanguangcheng/workerman-server library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

zhanguangcheng / workerman-server example snippets




use Zane\WorkermanServer\Server;


    'class' => WebApplication::class,
    'name' => 'WebApplication',
    'listen' => 'http://127.0.0.1:9001',
]);

$server->run();



namespace samples;

use Workerman\Connection\TcpConnection;
use Workerman\Worker;

class WebApplication extends Worker
{
    public function onMessage(TcpConnection $connection, mixed $request): void
    {
        $connection->send("Hello WorkermanServer");
    }
}

workerman-server
/
├─src
│  ├─applications
│      ├─HelloApplication.php    示例应用
│  └─middlewares                 中间件相关
│      ├─Middleware.php          中间件管理
│      ├─MiddlewareInterface.php 中间件接口
│      ├─RateLimiter.php         限流中间件
│      ├─StaticFile.php          静态文件中间件
|  └─Server.php                  服务管理
|  └─Monitor.php                 热重载监控
|  └─Helper.php                  帮助类
|  └─DotEnv.php                  环境变量管理
├─tests                          测试用例
│   ...
bash
php start.php