使用Guzzle使用PHP进行异步查询,而不必等待结果。
如何将JSON内容检索到另一个PHP文件中?
<?php
require '/tools/guzzle-master/vendor/autoload.php';
use GuzzleHttp\Client;
use GuzzleHttp\Psr7\Request;
$url = 'https://xxxxxxx/receive.php;
/*creating a client*/
$client = new Client();
/*JSON formatting */
$param = array(
'order_id' => 4544,
'type' => 0,
'amount' => 1266,
'fullname' => 'qdxeq',
'account' => 'dqad',
'callback_url' => 'http://yuexingy.top/Withdraw/WithdrawCallback.aspx',
'device_type' => 'dqd',
'device_id' => 'dafwe',
'device_ip' => 'dwe',
);
$json = json_encode($param);//json encoding
$data = array('json'=>$json);
$req = new Request('POST',$url, $data);
//sending the asynchronous request
$promise = $client->sendAsync($req,['timeout' => 10])->then(function ($response) {
echo 'I completed! ' . $response->getBody();
});
$promise->wait();
?>