-
-
Save PeeHaa/72a711a3191623410bb2d2621e52a276 to your computer and use it in GitHub Desktop.
foo.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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