composer require mpyw/co:^1.5
php index.php
<?php | |
//$ composer require mpyw/co:^1.5 | |
require __DIR__ . '/vendor/autoload.php'; | |
use mpyw\Co\Co; | |
use mpyw\Co\CURLException; | |
function curl($url, $ops = []) { | |
$ch = curl_init(); | |
curl_setopt_array($ch, | |
array_replace([ | |
CURLOPT_URL => $url, | |
CURLOPT_RETURNTRANSFER => true | |
], $ops)); | |
return $ch; | |
} | |
$urls = [ | |
"bitebtc"=> function(){ | |
$data = yield curl("https://bitebtc.com/api/v1/ticker/?market=BELL_btc"); | |
return json_decode($data)->result; | |
}, | |
"bitflyer" => function() { | |
$data = yield curl("https://api.bitflyer.com/v1/ticker"); | |
return json_decode($data); | |
} | |
]; | |
$datas = Co::wait($urls); | |
/* | |
bell -> btc | |
btc -> jpy | |
*/ | |
$price = $datas["bitebtc"]->price; | |
$price *= $datas["bitflyer"]->ltp; | |
echo $datas["bitebtc"]->price." bell/btc".PHP_EOL; | |
echo $datas["bitflyer"]->ltp." btc/jpy".PHP_EOL; | |
echo $price." JPY"; |