PHP code example of axios / tpr-workerman

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

    

axios / tpr-workerman example snippets



namespace demo;

server\WorkermanServer;

App::registerServer('workerman', WorkermanServer::class);

App::drive('workerman')->run();



declare(strict_types = 1);

namespace demo;

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 t'     => '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();