PHP code example of ncwsky / http-for-php

1. Go to this page and download the library: Download ncwsky/http-for-php 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/ */

    

ncwsky / http-for-php example snippets


#!/usr/bin/env php

define('LOG_PATH', __DIR__.'/log');

WorkerManSrv(

#!/usr/bin/env php

define('LOG_PATH', __DIR__.'/log');

WorkerManSrv(

    return [
        'name' => 'Demo', //服务名
        'ip' => '0.0.0.0', //监听地址
        'port' => 6502, //监听地址
        'init_php' => __DIR__.'/base.php', //初始文件
        'php_run' => function($req, $connection=null) {} //请求处理匿名函数 或 在初始文件时定义request_php_run请求处理函数【可reload】
        'setting' => [
            'count' => 20,    // 异步非阻塞CPU核数的1-4倍最合理 同步阻塞按实际情况来填写 如50-100
            #'task_worker_num' => 10, //异步任务进程数 配置了异步处理才能生效  异步处理耗时过多的会阻塞后续的异步处理请求
            #'max_request' => 500, //最大请求数 默认0 进程内达到此请求重启进程 可能存在不规范的代码造成内存泄露 这里达到一定请求释放下内存
            'stdoutFile' => __DIR__ . '/http.log', //终端输出
            'pidFile' => __DIR__ . '/http.pid',
            'logFile' => __DIR__ . '/http.log', //日志文件
            # 'user' => 'www', //设置worker/task子进程的进程用户 提升服务器程序的安全性
        ]
    ]