API consumption with multiple requests

Asked

Viewed 518 times

0

Good morning!

I need to make several requests in a REST API, using PHP, passing multiple parameters. currently I make one foreach using a variable in the url.

However due to processing time and error returned Fatal error: Maximum Execution time of 30 Seconds exceeded in.

I’ve tried increasing max_execution_time, max_input_time and memory_limit, worked for a while, however when requests increase and need to increase parameter values again, making it impracticable.

I wonder if there are possibilities to do it more efficiently, currently I do it as follows:

EX: I have a list of Zip Codes and I need to consult the API to know Address for them and return in a list.

foreach($registros -> result() as $consulta):
  $url = "https://webmaniabr.com/api/1/cep/{$consulta->cep}";
  $json = file_get_contents($url);
  $result = json_decode($json);
endforeach;
  • In the API documentation it says: "WebmaniaBR® applies a limit of up to 10 requests per second and 5,000 requests per day in the API..." it is not better to use another API?

  • I used this API only as an example, to make it easier to understand, the one that I actually use in the project and the FIPE table, which has no request limit. The limitation is on account of the same execution time, as I said, when I increase the max_execution_time it works, but then I have to put a very high value, and when it reaches again I have to increase again

  • Got it... but, there’s no way you can send a json with a request array at once instead of a foreach? I think this should be the way!

  • 1

    Have you tried using the curl_multi_exec? How many requests are there now? Depending on what you want to do, it’s not even worth using PHP.

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.