PHP code example of yii2-extensions / road-runner

1. Go to this page and download the library: Download yii2-extensions/road-runner 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/ */

    

yii2-extensions / road-runner example snippets




declare(strict_types=1);

ttp\Application;
use yii2\extensions\roadrunner\RoadRunner;

// production default (change to 'true' for development)
defined('YII_DEBUG') or define('YII_DEBUG', false);
// production default (change to 'dev' for development)
defined('YII_ENV') or define('YII_ENV', 'prod');




declare(strict_types=1);

use yii2\extensions\debug\WorkerDebugModule;

if (YII_ENV_DEV) {
    // configuration adjustments for 'dev' environment
    $config['bootstrap'][] = 'debug';
    $config['modules']['debug'] = [
        'class' => WorkerDebugModule::class,
        // uncomment the following to add your IP if you are not connecting from localhost.
        //'allowedIPs' => ['127.0.0.1', '::1'],
    ];
}



declare(strict_types=1);

use yii2\extensions\psrbridge\http\{Response, UploadedFile};

final class FileController extends \yii\web\Controller
{
    public function actionUpload(): Response
    {
        $file = UploadedFile::getInstanceByName('avatar');

        if ($file !== null && $file->error === UPLOAD_ERR_OK) {
            // validate the file before saving; choose a server-controlled storage name
            $file->saveAs('@runtime/uploads/' . bin2hex(random_bytes(16)) . '.bin');
        }

        return $this->asJson(['status' => 'uploaded']);
    }
}
yaml
version: "3"
rpc:
    listen: "tcp://127.0.0.1:6001"
server:
    command: "php web/index.php"
    relay: pipes
http:
    address: "0.0.0.0:8080"
    headers:
        response:
            "Cache-Control": "no-cache"

    middleware:
        - static # serve files first
        - gzip # compress dynamic output

    static:
        dir: web
        forbid:
            - .php
            - .htaccess
    pool:
        num_workers: 1
        supervisor:
            max_worker_memory: 100
jobs:
    pool:
        num_workers: 2
        max_worker_memory: 100
    consume: {}

kv:
    local:
        driver: memory
        config:
            interval: 60
metrics:
    address: "127.0.0.1:2112"