Мой PHP-скрипт продолжает работать, хотя есть живой запрос curl.Я отправляю массив на внешний веб-сайт для обработки с помощью curl.
Я пытался изменить параметры curl и установить max_execution_time в php.ini и set_max_time (0) в моих сценариях, и они не дали никаких результатов.
$postfielddata = array(
'action' => 'masscreate',
'type' => $type,
'fields' => $fields,
'sessiontoken' => $_POST['sessiontoken'],
);
//I expected this to pause the script until all data in the $post variable has been processed on the external website
//external website that is being curled runs fine with other large operations
$result = $this->runCurl($postfielddata);
error_log("response from api: " . print_r($result));
if (!$result)
{
//this block executes immediately, not waiting for curl to finish above
error_log("here no result so redirect error");
$this->redirect_error($type, 'Invalid file uploaded.', $data);
return;
}
//curl function that is being called
private function runCurl($postfielddata)
{
$post = array( 'data' => json_encode($postfielddata) );
$url = $this->config->item('urlToCurl');
$ch = curl_init();
curl_setopt($ch,CURLOPT_URL, $url);
curl_setopt($ch,CURLOPT_POST, count($post));
curl_setopt($ch,CURLOPT_POSTFIELDS, http_build_query($post) );
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 0);
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_ANY);
curl_setopt($ch, CURLOPT_TIMEOUT_MS, 400);
curl_setopt($ch, CURLOPT_NOSIGNAL, 1);
curl_setopt($ch, CURLOPT_HEADER, FALSE);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, false);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
$result = curl_exec($ch);
$result = json_decode($result, true);
curl_close($ch);
return $result;
}
Я хочу, чтобы мой сценарий дождался завершения всех запросов curl, прежде чем продолжить.Что я могу сделать здесь?