0
Guys, I came up with the need to consume an API with a very large volume of data, and I need to do this from a language because the API has limitations, and I go from PHP.
The problem is that I need to make several requests and some of them end up giving error 429. When this error happens, I wanted to see it somehow without having to wait for the script to stop running, because sometimes it is more than 10 minutes running and it would be interesting to know what is happening.
To know what was the lost data I arrived at the solution of trying to debuggar half-nut:
$i = 0;
$log_file = fopen('arquivo-log', 'w');
while($i < 5) {
$req = curl_get('url-qualquer'); // função que eu utilizo, mas nao vem ao caso
$body = "HTTP Status: {$req['http_code']}, Request Time: $i \n-------------------\n";
fwrite($log_file, $body);
sleep(2); // para o script nao rodar muito rapido e eu poder visualizar a interação
$i++;
}
fclose($log_file);
But the file is written completely when the script is finished running. What I wanted was to see it written every time I got in the loop. I got this by making an Insert in a database, then I see the data being entered throughout the execution, but I do not believe that is the best solution.
Can someone help me? I am doing something wrong or it is impossible to do this since php is interpreted and then compiled completely before some output?
Or is there some other way to do it, maybe with an Xdebug and tals?
Thank you very much, friend, this is exactly what I needed, and since it is a script for an extreme case, the performance can be put aside, so the answer was perfect :D.
– andre_luiss