Skip to content

Instantly share code, notes, and snippets.

@PeeHaa

PeeHaa/foo.php Secret

Created May 24, 2017 19:06
Show Gist options
  • Save PeeHaa/72a711a3191623410bb2d2621e52a276 to your computer and use it in GitHub Desktop.
Save PeeHaa/72a711a3191623410bb2d2621e52a276 to your computer and use it in GitHub Desktop.
foo.php
<?php
// plain callback based (think JS callback hell)
asyncRequest("http://httpbin.org/ip", function($data) {
asyncRequest("http://pieterhordijk.com/report-ip/" . json_decode($data, true)['origin'], function($response) {
asyncExecute('INSERT INTO responses (result) VALUES (?)', $response['result']);
});
});
// coroutines (amphp)
$data = yield asyncRequest("http://httpbin.org/ip", function($data);
$response = yield asyncRequest("http://pieterhordijk.com/report-ip/" . json_decode($data, true)['origin'], function($response);
yield asyncExecute('INSERT INTO responses (result) VALUES (?)', $response['result']);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment