Skip to content

Instantly share code, notes, and snippets.

@mentos1386
Last active March 24, 2016 23:15
Show Gist options
  • Save mentos1386/5635122cb54718b4f881 to your computer and use it in GitHub Desktop.
Save mentos1386/5635122cb54718b4f881 to your computer and use it in GitHub Desktop.
Demo presentation of new Async
use OpenCrest\OpenCrest;
// --------------
// NEW Async mode
// We will monitor time
$asyncStart = microtime(true);
// Make use of new Async
OpenCrest::$async = True;
// Create 150 requests
for($i = 0; $i < 150; $i++)
{
OpenCrest::Alliances()->get();
}
// Vardump time that it took to create 150 requests
$timeAsync = microtime(true) - $asyncStart;
var_dump("Async time: ", $timeAsync);
// Make those requests
OpenCrest::asyncRun();
// Vardump time it took to make those 150 requests
$timeAsync = microtime(true) - $asyncStart;
var_dump("Async time after run: ", $timeAsync);
// Vardump successes and rejections
var_dump(sizeof(OpenCrest::$asyncResponsesPublic["success"]));
var_dump(sizeof(OpenCrest::$asyncResponsesPublic["rejected"]));
// -------------------
// OLD Synchronus mode
// We will monitor time
$asyncStart = microtime(true);
// Set mode back to Synchronous
OpenCrest::$async = False;
// Create 150 requests
for($i = 0; $i < 150; $i++)
{
OpenCrest::Alliances()->get();
}
// Vardump time that it took to make 150 requests
$timeAsync = microtime(true) - $asyncStart;
var_dump("Async time: ", $timeAsync);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment