Site icon Hip-Hop Website Design and Development

invoking wp-remote-get every tot seconds

I need to call wp_remote_get() every 5 seconds passing the same paramater,a id job . the reason is that query is very slow. so the query returns the job status: in execution or executed. every time I call the function wp_remote_get(), I echo the result(job status) as long as the GET returns a string with the substring ‘.csv’. If I find ‘.csv’ in my result I stop the cycle.

$my_job = xxxx;
do{
$my_query = wp_remote_get( 'http://xxxx/job_status.php?id='.$my_job);
$final_result = $my_query['body'];
echo $final_result;
sleep(5);
}while(strpos($final_result,'.csv')==false);

this code works; but it doesn’t echo every time I call wp_remote_get(). It does echo of all the results when It finds the substring ‘.csv’, not every 5 seconds. where I am wrong?

I need to echo every 5 seconds cause the user couldn’t wait for long time before having an answer from the file job_status.php , thank you