Guzzlephp承诺变量

时间:2017-05-28 00:07:00

标签: php guzzle

我需要将一个变量传递给promise

<?php
$var = 'test';
$client = new Client();
$request = new Request('POST', 'https://url/');
$promise = $client->sendAsync($request, $options)->then(function ($response) {
  $echo $var;
});
$promise->wait();

1 个答案:

答案 0 :(得分:3)

这不是一个选择吗? `

<?php

$var = 'test';
$client = new Client();
$request = new Request('POST', 'https://url/');
$promise = $client
    ->sendAsync($request, $options)
    ->then(
        function ($response)  use ( $var ) {
            echo $var;
        }
    );
$promise->wait();

`