Skip to content

PSR7 Worker Client for RoadRunner 2.0 application server.

License

Notifications You must be signed in to change notification settings

rafelangelo/roadrunner-http

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

22 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

RoadRunner

Total alerts

RoadRunner is an open-source (MIT licensed) high-performance PHP application server, load balancer, and process manager. It supports running as a service with the ability to extend its functionality on a per-project basis.

RoadRunner includes PSR-7/PSR-17 compatible HTTP and HTTP/2 server and can be used to replace classic Nginx+FPM setup with much greater performance and flexibility.

Official Website | Documentation

Repository:

This repository contains the codebase PSR-7 PHP workers. Check spiral/roadrunner to get application server.

Installation:

To install application server and HTTP codebase:

$ composer require spiral/roadrunner-http nyholm/psr7

You can use the convenient installer to download the latest available compatible version of RoadRunner assembly:

$ composer require spiral/roadrunner-cli --dev

To download latest version of application server:

$ vendor/bin/rr get

You can use any PSR-17 compatible implementation.

Example:

To init abstract RoadRunner worker:

<?php

require __DIR__ . '/vendor/autoload.php';

use Nyholm\Psr7\Response;
use Nyholm\Psr7\Factory\Psr17Factory;

use Spiral\RoadRunner\Worker;
use Spiral\RoadRunner\Http\PSR7Worker;


// Create new RoadRunner worker from global environment
$worker = Worker::create();

// Create common PSR-17 HTTP factory
$factory = new Psr17Factory();

//
// Create PSR-7 worker and pass:
//  - RoadRunner worker
//  - PSR-17 ServerRequestFactory
//  - PSR-17 StreamFactory
//  - PSR-17 UploadFilesFactory
//
$psr7 = new PSR7Worker($worker, $factory, $factory, $factory);

while ($request = $psr7->waitRequest()) {
    try {
        // Reply by the 200 OK response
        $psr7->respond(new Response(200, [], 'Hello RoadRunner!'));
    } catch (\Throwable $e) {
    
        // Reply by the 500 Internal Server Error response
        $psr7->respond(new Response(500, [], 'Something Went Wrong!'));
        
        // Report error to RoadRunner (optional)
        $worker->error((string)$e);
    }
}

Testing:

This codebase is automatically tested via host repository - spiral/roadrunner.

License:

The MIT License (MIT). Please see LICENSE for more information. Maintained by Spiral Scout.

About

PSR7 Worker Client for RoadRunner 2.0 application server.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • PHP 100.0%