PHP code example of reactphp-x / laravel-reactphp

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

    

reactphp-x / laravel-reactphp example snippets


[
    'server' => [
        'route_file' => '',
        'public_path' => base_path('public'),
        'options' => [
            'pid_file' => env('REACTPHP_PID_FILE', base_path('storage/logs/reactphp_server.pid')),
            'log_file' => env('REACTPHP_LOG_FILE', base_path('storage/logs/reactphp_server.log')),
            'daemonize' => env('REACTPHP_HTTP_DAEMONIZE', false),
        ],
    ],
    'middlewares' => [
        // Add your middleware here
    ],

]



// see https://github.com/clue/framework-x/

$app = app('reactphp.server');

$app->get('/', function () {
    return \React\Http\Message\Response::plaintext(
        "Hello wörld!\n"
    );
});

$app->get('/users/{name}', function (\Psr\Http\Message\ServerRequestInterface $request) {
    return \React\Http\Message\Response::plaintext(
        "Hello " . $request->getAttribute('name') . "!\n"
    );
});

shell
php artisan reactphp:http start

'route_file' => base_path('routes/api.php'),