Homec4science

Implement read streaming on HTTPSFutures

Authored by epriestley <git@epriestley.com> on Dec 12 2013, 23:31.

Description

Implement read streaming on HTTPSFutures

Summary: See D7723.

Test Plan:

<?php

require_once 'scripts/__init_script__.php';

$future1 = new HTTPSFuture('https://www.google.com/');
$future2 = new HTTPSFuture('https://www.facebook.com/');

$wait = 0.01; // In seconds. This is very small for demo purposes, a value
               // like "1" is probably better in practice.

$futures = array('google' => $future1, 'facebook' => $future2);
foreach (Futures($futures)->setUpdateInterval($wait) as $key => $future) {

  // This might be a periodic update, in which case $future will be null.
  // It might also be a future exiting, in which case $future will not be null.
  // In either case, let's read any data we can first.
  foreach ($futures as $key => $future) {
    $new_data = $future->read();
    // Throw the buffered data away after we read it.
    $future->discardBuffers();

    $len = strlen($new_data);
    echo "Got {$len} bytes from {$key}.\n";
    if (strlen($new_data)) {
      // Do something interesting with the data.
    }
  }

  // Now, check if a future exited.
  if ($future !== null) {
    // This future has exited. We should sleep for a bit and then restart it,
    // or whatever.
    echo "Future {$key} exited!\n";
  }
}

Reviewers: btrahan

Reviewed By: btrahan

CC: aran

Differential Revision: https://secure.phabricator.com/D7724

Details

Committed
epriestley <git@epriestley.com>Dec 12 2013, 23:31
Pushed
aubortMar 17 2017, 12:03
Parents
rPHUbf669d47fdb4: Add color output support for supported platforms on Windows
Branches
Unknown
Tags
Unknown

Event Timeline

epriestley <git@epriestley.com> committed rPHU8182cd18afc6: Implement read streaming on HTTPSFutures (authored by epriestley <git@epriestley.com>).Dec 12 2013, 23:31