axios / tpr-workerman
Workerman server handler for tpr framework
1.0.3
2021-04-24 14:10 UTC
Requires
- php: >=7.4
- axios/tpr: ~5.1.0
- workerman/workerman: ^4.0
Requires (Dev)
This package is auto-updated.
Last update: 2024-10-25 22:29:12 UTC
README
Require
- PHP >= 7.4
- workerman >= 4.0
Install
composer require axios/tpr-workerman
Usage
- Simple
<?php namespace demo; require_once __DIR__ . '/vendor/autoload.php'; use tpr\App; use tpr\server\WorkermanServer; App::registerServer('workerman', WorkermanServer::class); App::drive('workerman')->run();
- Complete Example
<?php declare(strict_types = 1); namespace demo; require_once __DIR__ . '/vendor/autoload.php'; use tpr\App; use tpr\Event; use tpr\Path; use tpr\server\WorkermanServer; use Workerman\Worker; Path::configurate([ 'root' => __DIR__, ]); App::debugMode(false); App::registerServer('workerman', WorkermanServer::class); App::drive('workerman'); // initialize App before initialize Event Event::on('worker_init', function (Worker $worker) { // handle worker object in here }); App::workerman() ->config([ 'namespace' => 'app', // app base namespace, ### this is required ### 'lang' => 'zh-cn', // default language set name 'cache_time' => 60, // global cache time for config&route data 'force_route' => false, // forces use routing 'remove_headers' => [], // remove some header before send response // for ServerHandler custom config. 'server_options' => [ 'protocol' => 'http', // support websocket | http | tcp | other custom protocol 'host' => '0.0.0.0', 'port' => 2346, 'worker' => 4, // the number of worker process 'context' => [], // for enable ssl : https://github.com/walkor/Workerman#enable-ssl 'options' => [], // properties of worker. https://github.com/walkor/workerman-manual/blob/master/english/src/worker-development/name.md ], 'response_config' => [], // response config, see detail on pr\models\ResponseModel. 'default_content_type_cgi' => 'html', // default content-type on cgi mode 'default_content_type_ajax' => 'json', // default content-type on api request 'default_content_type_cli' => 'text', // default content-type on command line mode 'dispatch_rule' => '{app_namespace}\{module}\controller\{controller}', // controller namespace spelling rule ]) ->run();
Events
License
The project is open-sourced software licensed under the MIT.