I'm working with an api in which I send a CURL request and it returns me a json the problem is that if I loop in PHP the server hangs and the rendering is very slow, one solution I found was the page separating it does the request and make a request at a time via ajax, however in this case after 3 thousand times the server also hangs. I need some idea so that I can do at least 20 thousand requests faster and without stopping the server. Anyone have any ideas?
Part of the code:
public function put($path, $body = null, $params = array()) {
$body = json_encode($body);
$opts = array(
CURLOPT_HTTPHEADER => array('Content-Type: application/json'),
CURLOPT_CUSTOMREQUEST => "PUT",
CURLOPT_POSTFIELDS => $body
);
$exec = $this->execute($path, $opts, $params);
return $exec;
}
while($i<$t){
$price = $arr_precos[$i];
$mlb = $arr_ids[$i];
$i++;
$edit = '/items/'.$mlb;
$body = array("price"=>$price);
$response = $meli->put($edit, $body, $params);
}
The code above runs the loop, the other way I found I use the same code but without the loop through PHP, I loop requests to a PHP file with that code via ajax.
Obs. Every part of request and data processing is done in PHP + MYSQL