PHP Classes

File: README.md

Recommend this page to a friend!
  Classes of Wolfy-J   roadrunner   README.md   Download  
File: README.md
Role: Example script
Content type: text/markdown
Description: Example script
Class: roadrunner
Run multiple tasks of PHP in parallel using Golang
Author: By
Last change:
Date: 6 years ago
Size: 2,634 bytes
 

Contents

Class file image Download

RoadRunner

Latest Stable Version GoDoc Build Status Go Report Card Scrutinizer Code Quality Codecov

High-performance PHP load balancer and process manager library for Golang.

Library allows you to embed PHP code into Golang applications as managed pool of stateless workers.

Features:

  • no external services, drop-in (based on Goridge)
  • load balancer, process manager and task pipeline
  • frontend agnostic (queue, REST, PSR-7, async php, etc)
  • works over TPC, unix sockets and standard pipes
  • automatic worker replacement and safe PHP process destruction
  • worker lifecycle management (create/allocate/destroy timeouts)
  • payload context and body
  • control over max jobs per worker
  • protocol, worker and job level error management (including PHP errors)
  • very fast (~250k calls per second on Ryzen 1700X over 16 threads)
  • works on Windows

Installation:

$ go get github.com/spiral/roadrunner
$ composer require spiral/roadrunner

Examples:

p, err := rr.NewPool(
    func() *exec.Cmd { return exec.Command("php", "worker.php", "pipes") },
    rr.NewPipeFactory(),
    rr.Config{
        NumWorkers:      uint64(runtime.NumCPU()),
        AllocateTimeout: time.Second,              
        DestroyTimeout:  time.Second,               
    },
)
defer p.Destroy()

rsp, err := p.Exec(&Payload{Body: []byte("hello")})
<?php
/
 * @var Goridge\RelayInterface $relay
 */

use Spiral\Goridge;
use Spiral\RoadRunner;

$rr = new RoadRunner\Worker($relay);

while ($body = $rr->receive($context)) {
    try {
        $rr->send((string)$body, (string)$context);
    } catch (\Throwable $e) {
        $rr->error((string)$e);
    }
}

> Check how to init relay here. More examples can be found in tests.

License:

The MIT License (MIT). Please see LICENSE for more information.