Skip to content
master
Go to file
Code

Latest commit

 

Git stats

Files

Permalink
Failed to load latest commit information.
Type
Name
Latest commit message
Commit time
 
 
etc
 
 
 
 
src
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

README.md

react-adapter

Build Status Coverage Status Stable License

amphp/react-adapter makes any ReactPHP library compatible with Amp.

Installation

composer require amphp/react-adapter

Usage

Everywhere where a ReactPHP library requires an instance of LoopInterface, you just pass ReactAdapter::get() to run the ReactPHP library on Amp's event loop.

<?php

require 'vendor/autoload.php';

use Amp\Loop;
use Amp\ReactAdapter\ReactAdapter;

Loop::run(function () {
    $app = function ($request, $response) {
        $response->writeHead(200, array('Content-Type' => 'text/plain'));
        $response->end("Hello World\n");
    };

    $socket = new React\Socket\Server(ReactAdapter::get());
    $http = new React\Http\Server($socket, ReactAdapter::get());

    $http->on('request', $app);
    echo "Server running at http://127.0.0.1:1337\n";

    $socket->listen(1337);
});

You can also use the adapter to run ReactPHP apps on an Amp event loop implementation without relying on Amp's global event loop.

$loop = new Amp\ReactAdapter\ReactAdapter((new Amp\Loop\DriverFactory)->create());

Documentation

Documentation is available on amphp.org/react-adapter.

Notes

If you need to convert an Amp promise to a ReactPHP promise, check the umbri/amp-react-interop package.

About

Adapter to make any ReactPHP library compatible with Amp.

Topics

Resources

License

Sponsor this project

 

Packages

No packages published

Contributors 4

  •  
  •  
  •  
  •  
You can’t perform that action at this time.