[英]What is the equivalent of curl_multi_exec in Guzzle?
I'm trying using the following curl function to create multiple webhooks at once using CURL which i think is making async calls that's why it processed so fast compared to do it using curl_exec, now i'm wondering how to get the same result using Guzzle
public function registerWebhooks()
{
$topics = [
'customers/create',
'customers/update',
'checkouts/create',
];
foreach ($topics as $topic) {
$params[] = [
'webhook' => [
'topic' => $topic,
'address' => SRC_PATH . 'includes1/webhook_handler.php',
'format' => 'json'
]
];
}
$url = 'https://' . $this->shop . '/admin/api/2020-04/webhooks.json';
$headers = array(
'Content-Type:application/json',
'X-Shopify-Access-Token:' . $this->token
);
$curly = array();
// data to be returned
$result = array();
$mh = curl_multi_init();
foreach ($params as $id => $d) {
$json_params = json_encode($d);
$curly[$id] = curl_init();
curl_setopt($curly[$id], CURLOPT_URL, $url);
curl_setopt($curly[$id], CURLOPT_HTTPHEADER, $headers);
curl_setopt($curly[$id], CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curly[$id], CURLOPT_POST, 1);
curl_setopt($curly[$id], CURLOPT_POSTFIELDS, $json_params);
curl_setopt($curly[$id], CURLOPT_CUSTOMREQUEST, 'POST');
curl_multi_add_handle($mh, $curly[$id]);
}
$running = null;
do {
curl_multi_exec($mh, $running);
} while ($running > 0);
foreach ($curly as $id => $c) {
$result[$id] = json_decode(curl_multi_getcontent($c));
curl_multi_remove_handle($mh, $c);
}
curl_multi_close($mh);
return $result;
}
您可以使用createRequest
,然后使用sendAll()
,这将使用curl_multi_exec
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.