Php 发送并行请求时在Guzzle上设置setAuth()

Php 发送并行请求时在Guzzle上设置setAuth(),php,rest,guzzle,Php,Rest,Guzzle,在Guzzle中发出请求时,您可以使用此设置用户名和密码: $request->setAuth($username, $password); 这对我的单一请求非常有效。现在我需要做一组并行请求,我不知道该如何设置。我已经为我的单个请求和并行请求设置了auth和Authorization头,正如我所说,单个请求可以工作,因为我可以设置$request->setAuth()。如何为并行请求设置setAuth(),或者是否需要使用其他东西 编辑这是我的代码 $client = new Clie

在Guzzle中发出请求时,您可以使用此设置用户名和密码:

$request->setAuth($username, $password);
这对我的单一请求非常有效。现在我需要做一组并行请求,我不知道该如何设置。我已经为我的单个请求和并行请求设置了
auth
Authorization
头,正如我所说,单个请求可以工作,因为我可以设置
$request->setAuth()
。如何为并行请求设置
setAuth()
,或者是否需要使用其他东西

编辑这是我的代码

$client = new Client('https://service.example.com/');

$username = 'username';
$password = 'password';
$auth = base64_encode($username . ":" . $password);
$dm = $_POST['domains'];
$domains = explode("\n", $dm);
$client->setDefaultOption('auth', array($username, $password, 'Any'));

$options = array(
'query' => array(
    'unit'=> 'y',
    'period' => $_POST['period'],
    'password' => urlencode($_POST['password']),
    'registrant' => 'abcdefg-00004'
),
'headers' => array(
    'Authorization' => 'Basic '.$auth,
    'Accept' =>'application/hal+json',
    'Access-Control-Allow-Origin' => '*'
),
'auth' => array($username, $password, 'Basic'),
'timeout' => '30',
'connect_timeout' => '10',
'cookies' => array('cert_url' => 'https://url.tocert.com/cert/su82jhdea3df5e81cd2cs8ejrae621b3a475312vd'),
'verify' => true,
'debug' => true,

);

$requests = array();
foreach($domains as $d){
        $requests[] = $client->post($_POST['server-name'].'/domain?method=POST&callback=?&name='.$d, array(), $options);
}

//Do it
try {
$bulk_create = $client->send($requests);

foreach($bulk_create as $create){
    echo $create->getBody();
}
} catch (MultiTransferException $e) {

echo "The following exceptions were encountered:\n";
foreach ($e as $exception) {
    echo $exception->getMessage() . "\n";
}

echo "The following requests failed:\n";
foreach ($e->getFailedRequests() as $request) {
    echo $request . "\n\n";
}

echo "The following requests succeeded:\n";
foreach ($e->getSuccessfulRequests() as $request) {
    echo $request . "\n\n";
}
}