oracle765 Posted July 1, 2015 Share Posted July 1, 2015 Hi professionals just after some advice on what to do for the best here We have a website that queries Expedia, Laterooms and a few other hotel APIs and displays the hotel results which is fine The problem is it takes a very long time and the user waits and waits and waits for the results to be displayed Is there a way to display some results asap to the user whilst the APIs are still querying and then the rest of the results once finished Or a way to build up the result set bit by bit Any advice if this is possible and where to start would be greatly appreciated Thanks in advance Alan Quote Link to comment https://forums.phpfreaks.com/topic/297131-php-advice-on-best-approach/ Share on other sites More sharing options...
scootstah Posted July 1, 2015 Share Posted July 1, 2015 The term you're looking for is "asynchronous". You can't delay output with PHP alone. Output is sent once the script is finished. You would need to use Javascript to accomplish this. There are a number of ways to solve this. You could use AJAX with JSONP. Or if the API's allow CORS, you can just use straight up AJAX. Or, you could have a PHP script run in the background and then use AJAX to call that script. Quote Link to comment https://forums.phpfreaks.com/topic/297131-php-advice-on-best-approach/#findComment-1515362 Share on other sites More sharing options...
CroNiX Posted July 1, 2015 Share Posted July 1, 2015 @scootstah, not sure what you mean by "output is sent once the script is finished". I believe that's only the case if you're using output buffering? Quote Link to comment https://forums.phpfreaks.com/topic/297131-php-advice-on-best-approach/#findComment-1515386 Share on other sites More sharing options...
scootstah Posted July 1, 2015 Share Posted July 1, 2015 I mean that you cannot send output, wait for the API calls, and then send some more output. Output buffering can be used to order the output, but it still has to wait for the script to finish. Quote Link to comment https://forums.phpfreaks.com/topic/297131-php-advice-on-best-approach/#findComment-1515388 Share on other sites More sharing options...
oracle765 Posted July 2, 2015 Author Share Posted July 2, 2015 ok I will look into this So there is no way to poll them as sessions or something thanks again Quote Link to comment https://forums.phpfreaks.com/topic/297131-php-advice-on-best-approach/#findComment-1515453 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.