curl_multi добавление нулевого значения в пост Json

Я отправляю параллельные запросы, используя curl_multi_init, curl_multi_add_handle, curl_multi_exec, curl_multi_select, curl_multi_getcontent, curl_multi_remove_handle а также curl_multi_close, Данные идеальны, когда я выполняю json_encode (), но после того, как я отправляю их на другой сервер, массив json имеет дополнительное нулевое значение в конце, что приводит к разрыву системы. Похоже, что функции curl muti вводят нулевое значение в конце. Кто-нибудь имел эту проблему раньше или знает ответ на это?

Код выглядит так:

public function curlMulti($data)
{
$multi = curl_multi_init();
$channels = array();

// Loop through the array, create curl-handles
// and attach the handles to our multi-request
foreach ($data as $oneData) {
$ch = curl_init();
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Authorization: Token token="' . $this->_api_token . '"'
));

curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch,CURLOPT_POST, 1);

$oneData = json_encode($oneData);

curl_setopt($ch,CURLOPT_POSTFIELDS, $oneData);
curl_multi_add_handle($multi, $ch);
$channels[] = $ch;
}

// While we're still active, execute curl
$active = null;
do {
$mrc = curl_multi_exec($multi, $active);

}  while ($mrc == CURLM_CALL_MULTI_PERFORM);

while ($active && $mrc == CURLM_OK) {
// Wait for activity on any curl-connection
if (curl_multi_select($multi) == -1) {
continue;
}

// Continue to exec until curl is ready to
// give us more data
do {
$mrc = curl_multi_exec($multi, $active);
} while ($mrc == CURLM_CALL_MULTI_PERFORM);
}

// Loop through the channels and retrieve the received
// content, then remove the handle from the multi-handle
foreach ($channels as $channel) {
$response[] =  curl_multi_getcontent($channel);
curl_multi_remove_handle($multi, $channel);
}

foreach($response as $key => $oneResponse) {
$response[$key] = json_decode($oneResponse, true);
}

// Close the multi-handle and return our results
curl_multi_close($multi);

return $response;
}

0

Решение

Задача ещё не решена.

Другие решения

Других решений пока нет …

По вопросам рекламы ammmcru@yandex.ru
Adblock
detector