使用Guzzle以异步模式获取请求

时间:2017-10-02 13:25:42

标签: php laravel guzzle

我将以下代码作为:

public function postGuzzleRequest()
{
    $client = new \GuzzleHttp\Client();
    $url = "http://myexample.com/api/posts";
    $myBody['name'] = "Demo";
    $request = $client->post($url,  ['body'=>$myBody]);
    $response = $request->send();
    dd($response);
}

现在我试图在异步模式下使用它

1 个答案:

答案 0 :(得分:0)

直接从doc获取: http://docs.guzzlephp.org/en/stable/quickstart.html

$promise = $client->getAsync('http://httpbin.org/get');
$promise = $client->deleteAsync('http://httpbin.org/delete');
$promise = $client->headAsync('http://httpbin.org/get');
$promise = $client->optionsAsync('http://httpbin.org/get');
$promise = $client->patchAsync('http://httpbin.org/patch');
$promise = $client->postAsync('http://httpbin.org/post');
$promise = $client->putAsync('http://httpbin.org/put');