使用 guzzle 测试并发时遇到的一个关于 PHP return 的问题
代码如下#
require './vendor/autoload.php';
use GuzzleHttp\Client;
use GuzzleHttp\Promise;
$client = new Client(['base_uri' => '127.0.0.1/']);
// Initiate each request but do not block
$promises = [
'test1' => $client->getAsync('test.php?id=1')
];
// Wait on all of the requests to complete.
$results = Promise\unwrap($promises);
// You can access each result using the key provided to the unwrap
// function.
die(var_dump($results['test1']->getBody()->getContents()));
test.php 文件如下#
$id = $_GET['id'];
class test{
public function __construct($id)
{
$this->id = $id;
}
public function handle()
{
//return $this->id;
echo $this->id;
}
}
$result = new test($id);
$result ->handle();
推荐文章: