PHP code example of salamander / webworker

1. Go to this page and download the library: Download salamander/webworker 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/ */

    

salamander / webworker example snippets



use Workerman\Worker;
use Workerman\Protocols\Http;
use WebWorker\Libs\Mredis;
use WebWorker\Libs\Mdb;
use WebWorker\Libs\Mmysqli;

define('APP_ROOT', str_replace('\\', '/', dirname(__FILE__)));
tLengthHeader' => false, // Allow the web server to send the content-length header,
        'determineRouteBeforeAppMiddleware' => true
    ]
];

$app = new WebWorker\App("http://0.0.0.0:8888", [], $containerConfig);

$app->name = "newSayu66";

$app->count = 30;

$app->max_request = 1000;

//设置监控
$app->statistic_server = "udp://127.0.0.1:55656";

$app->get('/', function ($req, $res) {
    $res->getBody()->write('hello salamander');
});

$app->get('/name', function ($req, $res) {
    $res->getBody()->write('hello name');
});

//初始化redis和mysqli连接
$app->onWorkerStart = function($worker) {

};

$app->onWorkerReload = function ($worker) {

};


// 如果不是在根目录启动,则运行runAll方法
if(!defined('GLOBAL_START'))
{
    Worker::runAll();
}