Skip to content

Instantly share code, notes, and snippets.

Avatar

Niklas Keller kelunik

View GitHub Profile
View concurrent-requests.php
<?php
require __DIR__ . '/vendor/autoload.php';
use Amp\Loop;
use Amp\Artax;
$queue = new SplQueue;
$waiting = new Amp\Deferred;
$http = new Artax\DefaultClient;
View infection.log
____ ____ __ _
/ _/___ / __/__ _____/ /_(_)___ ____
/ // __ \/ /_/ _ \/ ___/ __/ / __ \/ __ \
_/ // / / / __/ __/ /__/ /_/ / /_/ / / / /
/___/_/ /_/_/ \___/\___/\__/_/\____/_/ /_/
Running initial test suite...
PHPUnit version: 6.5.7
View server.php
<?php
use Amp\Iterator;
use Amp\Cluster\Listener;
use Psr\Log\LoggerInterface as PsrLogger;
Amp\Loop::run(function () {
if (Amp\Cluster::isWorker()) {
$socket = yield Amp\Cluster::listen("tcp://0.0.0.0:8080");
$logger = Amp\Cluster::getLogger();
View stream-to-iterator.php
<?php
use Amp\Emitter;
use Amp\Iterator;
use Amp\Promise;
class CsvReader implements Iterator {
/** @var EventEmitter */
private $eventEmitter;
View example.php
<?php
require __DIR__ . "/vendor/autoload.php";
$http = new Amp\Artax\Client;
$promises = [
async $http->request("https://google.com/"),
async $http->request("https://stackoverflow.com/"),
];
View react-adapter.md

You can use amphp/react-adapter + amphp/amp, which will give you an ev based implementation – if ev is installed – that is fully compatible with ReactPHP's LoopInterface.

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

// $loop is now a ReactPHP compatible driver based on ext-ev

If you don't want the automatic driver selection based on the available extensions, you can also instantiate a driver on your own using $driver = new Amp\Loop\EvDriver;.

@kelunik
kelunik / polygon.txt
Created Feb 20, 2018
Polygon Intersection
View polygon.txt
______
____/ \
/ \ |
| | /
\_____|____/
View php.sh
#!/bin/bash
set -e
set -x
rm -rf ~/.php-build
mkdir ~/.php-build
cd ~/.php-build
if [ $1 == "master" ]
View then-httplug.php
<?php
require __DIR__ . "/vendor/autoload.php";
use Amp\Promise;
$client = new Http\Adapter\Artax\Client;
$request1 = new GuzzleHttp\Psr7\Request("GET", "http://example.com/");
View artax-adapter.php
<?php
require __DIR__ . "/vendor/autoload.php";
use Amp\Promise;
$client = new Http\Adapter\Artax\Client;
$responses = Promise\wait(Promise\all([
$client->sendAsyncRequest($request1);