Skip to content

Instantly share code, notes, and snippets.

@mykiwi
Forked from igorw/client-slow.php
Last active December 16, 2015 21:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mykiwi/5498457 to your computer and use it in GitHub Desktop.
Save mykiwi/5498457 to your computer and use it in GitHub Desktop.
<?php
require __DIR__.'/vendor/autoload.php';
use React\Curry\Util as Curry;
$projects = array(
'react-php/react',
'cboden/Ratchet',
'nrk/predis-async',
'bergie/dnode-php',
'umpirsky/wisdom',
'igorw/evenement',
);
$fullRequest = function ($url, $callback) {
$callback(file_get_contents($url));
};
$parseResponse = function ($project, $body) {
$decoded = json_decode($body, true);
$latest = $decoded[0]['commit'];
$author = $latest['author']['name'];
$date = date('F j, Y', strtotime($latest['author']['date']));
$message = preg_replace('#\n.*$#s', '', $latest['message']);
printf("\n");
printf("Latest commit on %s was done by %s on %s\n", $project, $author, $date);
printf("%s\n", $message);
};
printf("I'm telling you about %s projects.\n", count($projects));
foreach ($projects as $project) {
$url = "https://api.github.com/repos/$project/commits";
$fullRequest($url, Curry::bind($parseResponse, $project));
}
<?php
require __DIR__.'/vendor/autoload.php';
use React\Curry\Util as Curry;
$loop = React\EventLoop\Factory::create();
$dnsResolverFactory = new React\Dns\Resolver\Factory();
$dnsResolver = $dnsResolverFactory->createCached('8.8.8.8', $loop);
$factory = new React\HttpClient\Factory();
$client = $factory->create($loop, $dnsResolver);
$projects = array(
'react-php/react',
'cboden/Ratchet',
'nrk/predis-async',
'bergie/dnode-php',
'umpirsky/wisdom',
'igorw/evenement',
);
$fullRequest = function ($url, $callback) use ($client) {
$request = $client->request('GET', $url);
$request->on('response', function ($response) use ($callback) {
$buffer = '';
$response->on('data', function ($data) use (&$buffer) {
$buffer .= $data;
});
$response->on('end', function () use (&$buffer, $callback) {
$callback($buffer);
});
});
$request->end();
};
$parseResponse = function ($project, $body) {
$decoded = json_decode($body, true);
$latest = $decoded[0]['commit'];
$author = $latest['author']['name'];
$date = date('F j, Y', strtotime($latest['author']['date']));
$message = preg_replace('#\n.*$#s', '', $latest['message']);
printf("\n");
printf("Latest commit on %s was done by %s on %s\n", $project, $author, $date);
printf("%s\n", $message);
};
printf("I'm telling you about %s projects.\n", count($projects));
foreach ($projects as $project) {
$url = "https://api.github.com/repos/$project/commits";
$fullRequest($url, Curry::bind($parseResponse, $project));
}
$loop->run();
{
"repositories": [
{
"type": "vcs",
"url": "https://github.com/arnaud-lb/react"
}
],
"minimum-stability": "dev",
"require": {
"react/react": "dev-http-client",
"react/curry": "dev-master"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment