RoadRunner PHP is an emerging application server, written in Golang. The software is configured that Go’s HTTP handler precedes HTTP request, and the load balancer / process manager allocates the request to PHP’s worker. Spiral Scout, the author of RoadRunner, realized that the power of Golang can be realized in the development stack, and it would be possible to enhance existing PHP apps with the power of Golang. It seems that it was an opportunity for development. And in addition to regular HTTP servers, RoadRunner’s implementation of gRPC servers is also open to show the new potential of PHP.

The software provides lightning fast speed, enhanced stability, powerful performance. Some of the features of the software includes :

  • Production Ready : Not only is RoadRunner the product of years of planning, testing, and coding, it is also currently being used for massive enterprise-level projects that constantly experience heavy loads. You can install it and have it running in production in your application today.
  • High Performance : it will maximize your application’s performance by leveraging Golang’s goroutines and multi-threading to speed up processing while reducing actual server load. This boosts performance and significantly cuts back on development resources.
  • No Extensions Required : Forget about custom builds or installing extensions to get RoadRunner PHP to work. Any application using a version of PHP7 or higher will seamlessly integrate with RoadRunner in seconds.
  • HTTP middleware : Create custom HTTP Middleware in RoadRunner to handle the heavy lifting of specific use cases like rate-limiting and JWT parsing for your application before it even reaches PHP!
  • Logging and reporting :  Use RoadRunner’s internal event system to collect and manage application logs, monitor performance, and handle fatal errors.
  • AWS Lambda : Ship RoadRunner binary with your PHP Lambda function to profoundly improve performance by reusing parts of your PHP application in multiple contexts
  • Any Library : Integrate any existing Golang library with your PHP application using our Goridge RPC protocol.
  • GRPC : Use PHP-GRPC to implement high-performance gRPC APIs for your application.
  • Queue : Implement Spiral/Jobs package to allow RoadRunner to operate as a queue consumer supporting in-memory queue, AMQP, Amazon SQS, and Beanstalk.
     

Application Performance.

RoadRunner PHP is one of the fastest ways to run your PHP application (see the following independent research).

Roadrunner PHP

It is designed to withstand a high load while still being available 100% of the time.

Roadrunner PHP usage

To get started with RoadRunner you can download the prebuitd binary or build it with Go. The easy way is by running a docker instance :

FROM php:7.2-cli

RUN apt-get update && apt-get install -y --no-install-recommends \
  wget \
  git \
  vim \
  zlib1g-dev \
  unzip

# Install Go
RUN wget -O - https://dl.google.com/go/go1.11.4.linux-amd64.tar.gz | tar -C /usr/local -xzf -
ENV PATH $PATH:/usr/local/go/bin
ENV GO111MODULE on

# Install RoadRunner
WORKDIR /go/src
RUN git clone --depth 1 https://github.com/spiral/roadrunner \
  && cd /go/src/roadrunner \
  && make \
  && make install
COPY ./.rr.yaml /etc/roadrunner/.rr.yaml

# Install PHP Extensions
RUN docker-php-ext-install zip \
  && docker-php-ext-install opcache \
  && docker-php-ext-enable opcache

# Install Composer
RUN php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');" \
  && php -r "if (hash_file('SHA384', 'composer-setup.php') === rtrim(file_get_contents('https://composer.github.io/installer.sig'))) { echo 'Installer verified'; } else { echo 'Installer corrupt'; unlink('composer-setup.php'); } echo PHP_EOL;" \
  && php composer-setup.php \
  && php -r "unlink('composer-setup.php');" \
  && mv composer.phar /usr/local/bin/composer

WORKDIR /var/www

ENTRYPOINT ["/usr/local/bin/rr", "serve", "-c", "/etc/roadrunner/.rr.yaml"]

It is based on the image for PHP, but I also include Go 1.11 for the RoadRunner build.

You can start the environment easily by docker-compose by cloning the following Git repository.

$ git clone https://github.com/n1215/roadrunner-docker-skeleton

Then  in the RoadrRunner configuration file, a file that is an entry point for PHP Worker is specified :

http:
  address: :8080
  workers:
    command: "php /var/www/app/psr-worker.php"
    pool:
      numWorkers: 4

Finally it is basic to describe the processing to receive PSR-7 request and return PSR-7 response in that file :

<?php
declare(strict_types=1);

ini_set('display_errors', 'stderr');
include 'vendor/autoload.php';

$relay = new Spiral\Goridge\StreamRelay(STDIN, STDOUT);
$psr7 = new Spiral\RoadRunner\PSR7Client(new Spiral\RoadRunner\Worker($relay));

while ($req = $psr7->acceptRequest()) {
    try {
        $resp = new \Zend\Diactoros\Response();
        $resp->getBody()->write('Hello, world!');
        $psr7->respond($resp);
    } catch (\Throwable $e) {
        $psr7->getWorker()->error((string)$e);
    }
}

More information could be found in the documentation, download here. Released under an MIT license.

LEAVE A REPLY

Please enter your comment!
Please enter your name here