Using Roadrunner laravel on windows

Posted by nakins on Mon, 13 Dec 2021 11:36:54 +0100

1, Preparatory work

1. Install composer and set the image

Packgist / composer China full image (pkg.xyz)

2. The version of laravel was found when searching spiral/roadrunner

RoadRunner source address

Roadrunner laravel source address

3. Decided to try spiral / Roadrunner laravel and read the dependency requirements of the released version,

Latest version supported by PHP ^ 7.3 | ^ 8.0: v3 seven

Latest version supported by PHP ^ 7.4 | ^ 8.0: V5 five

PHP needs to be turned on_ socket. DLL extension. If the php -m view extension does not exist, add it manually

2, Start practice

Note: it runs in the windows environment, an integrated environment built by phpstudy, and the web server is nginx, php ^7.3

  1. Test a new project and install the laravel framework

    Using the existing nginx server, configure the virtual domain name test Dy.com and ensure that the project can be used

  2. introduce spiral/ Roadrunner laravel package

    composer require spiral/roadrunner-laravel "^3.7.0"

  3. Publish the configuration file, execute php artisan vendor:publish, select the corresponding number of spiral \ Roadrunner lavel \ serviceprovider and enter it. There will be two file changes, as shown below

  4. Copy rr.yaml. Rename dist to rr.yaml

  5. Download the Roadrunner executable

    .\vendor\bin\rr get-binary

RoadRunner is implemented in Go language and can only be used when it is finally compiled into binary files. Various versions of compiled executable files are officially provided.

This \vendor\bin\rr opens it with an editor and finds that it is a php program. To use RoadRunner as a web server, you must first run it, just like starting the apache/nginx server.

5.1 if the download is unsuccessful, the prompt is as follows:

"Unable to extract this file", unable to download? Unable to unzip?

According to the version prompt in the figure, in vendor / spiral / Roadrunner / bin / RR Found a source in PHP,

public static function getSignature(): string
{
    return 'roadrunner-' . self::getVersion() . '-' . self::getOSType() . '-amd64';
}

public static function getBinaryDownloadUrl(): string
{
    $ext = '.zip';
    if (self::getOSType() == 'linux') {
        $ext = '.tar.gz';
    }

    return 'https://github.com/spiral/roadrunner/releases/download/v'
        . static::getVersion() . '/' . self::getSignature()
        . $ext;
}

5.2 according to the version prompted in the figure, find the corresponding version of the source code in github, and then download the compiled versions below. Click download and unzip

roadrunner-1.9.1-windows-amd64.zip

  1. The extracted RR Exe file and put it in the root directory of the project

  2. Modification rr.yaml configuration file, delete some configurations and keep necessary

http:
  address: 0.0.0.0:80

  workers:
    # linux version
    #command: "php ./vendor/bin/rr-worker start --relay-dsn unix:///var/run/rr-relay.sock"
      #relay: "unix:///var/run/rr-relay.sock"

      # windows version
    command: "php vendor/spiral/roadrunner-laravel/bin/rr-worker start pipes"

    # connection method (pipes, tcp://:9000, unix://socket.unix). default "pipes"
    relay: "pipes"
    user: ""
    pool:
      numWorkers: 4
      maxJobs: 0
      allocateTimeout: 60
      destroyTimeout: 60

static:
  dir: "public"
  forbid: [ ".php", ".htaccess" ]
  request:
    "Example-Request-Header": "Value"
  response:
    "X-Powered-By": "RoadRunner"
  1. Under the project root directory, start the service

rr.exe serve -v -d -c ./.rr.yaml

[as shown]

3, Testing

  1. First, use the default routing test after the framework is installed,

    Route::get('/', function () {
        return view('welcome');
    });

  1. Modify the content in the view, and the data will change without restarting the service.

  2. welcome. blade. Add a form to the PHP view

    <body class="antialiased">
        <h1>post login 12</h1>
        <form method="post" action="/login">
            @csrf
            user name:<input type="text" name="username" value="lisi"/>
            Age:<input type="text" name="age" value="10"/>
            <button type="submit">Submit</button>
        </form>
    </body>
  3. Modify the route file route / Web PHP, an error is reported after submission on the browser

    Route::post('/login', function (\Illuminate\Support\Facades\Request $request) {
        return $request->all();
    });
  4. Therefore, the routing content was modified, and the routing cache was cleared using PHP artist route: clear. It was found that the error was still reported

    Route::post('/login', function (\Illuminate\Support\Facades\Request $request) {
        return request()->input();
    });
  5. Then the command line ctrl+c disconnects the service and re executes the command RR exe serve -v -d -c ./. rr. Yaml, so it is normal and new data is obtained

  6. After several tests, it was found that the service did not load the latest configuration

  7. Yes rr. The following contents are added to the yaml file for automatic refresh. Pay attention to the comments in the configuration.

reload:
  interval: 1s
  patterns: [ ".php" ]
  services:
    http:
      # The configured routing file is reloaded and configured on demand. It is not recommended to configure it as' '
      dirs: [ "routes" ]
      recursive: true

Topics: Laravel