I am currently working with a really really slow API and in many instances the website users have to wait for those to finish. E.g. when a contact form is sent and the information is sent via the API.
Now, I am wondering how I can speed the API calls up, at least for the user? Is it ok, do make an asynchronous AJAX-call to a separate PHP-file and make the API-call from there? If so, what happens if the user closes the page, while the API-call is still running? He might think, that everything is already sent.
Yes, definitely; that would be the best way.
It likely is sent; the PHP script running the API call continues on its merry way, and it’s only when it tries to send a response back (a confirmation or error, likely) that it finds the client went away. If the API call generates an email eventually, it will complete whether the user waits or not (unless there’s an error in the API call itself).