2017 © Pedro Peláez
 

library futures

Make asynchronous http requests or run system commands asynchronously!

image

hazbo/futures

Make asynchronous http requests or run system commands asynchronously!

  • Friday, August 30, 2013
  • by hazbo
  • Repository
  • 1 Watchers
  • 3 Stars
  • 9 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 1 Versions
  • 0 % Grown

The README.md

Futures

Define: Futures -, (*1)

"Futures (also known as "promises") are objects which act as placeholders for some future result of computation. They let you express parallel and asynchronous execution with a natural syntax. There are three provided concrete Future implementations: ExecFuture for executing system commands, HTTPFuture for making HTTP requests, and QueryFuture for executing database queries." - Facebook, (*2)

This is all true, however this library only supports http requests and the ability to execute system commands, asynchronously (or synchronously)., (*3)

What is it?

This set of files was originaly forked from Facebook's libphutil which has some pretty nifty little tools, you should go check it out!, (*4)

These libraries are for everything in the src/future so I've namespaced them up, cleaned up the code to follow PSR standards (not finished!) and have only tested a very small part of it; making http requests., (*5)

Install

You can add this component to your project using composer:, (*6)

{
    "require" : {
        "hazbo/futures" : "dev-master"
    }
}

composer install or php composer.phar install, (*7)

Asynchronously

<?php
require_once('path/to/vendor/autoload.php');

use Hazbo\Component\Http\HttpFuture;

$future = new HttpFuture('http://graph.facebook.com/zuck');
$future->start();

// Check to see if the request has finished
var_dump($future->isReady());

// Hang back a second
sleep(1);

// Lets check again...
var_dump($future->isReady());

// One more sec!
sleep(1);

// Should be ready now!
var_dump($future->isReady());

So above we can see what is going on, pretty straight forward. We can call:, (*8)

  • start()
  • isReady()
  • resolve()

Calling resolve will wil block the future until it has finished processing the request, so essentially acting synchronously. start will fire off the request and you can then check the progress of this using isReady., (*9)

Synchronously

<?php
require_once('path/to/vendor/autoload.php');

use Hazbo\Component\Http\HttpFuture;

$future = new HttpFuture('http://graph.facebook.com/zuck');
list($body, $headers) = $future->resolvex();

echo $body;

So above we are just making a synchronous request, it will block until the request has finished., (*10)

I don't know how well I've explained this... but it's awesome! Credit to the guys at Facebook who started this off. Feel free to contribute!, (*11)

Disclaimer

I have not yet finished off the code for performing system commands! I'm working real hard on it though., (*12)

I need help to tidy up some of the code!... please help., (*13)

The Versions

30/08 2013

dev-master

9999999-dev

Make asynchronous http requests or run system commands asynchronously!

  Sources   Download

The Requires

  • php >=5.3.0

 

commands http exec request asynchronous system hazbo futures