I have a PHP script that is run through an AJAX call, and it can sometimes take very long (up to 30 seconds) for some people. To help keep the visitor's attention, I show a progress bar of how far along the process is, as well as listing random facts about the what the web app does, etc etc.
In order to update the progress bar to show exactly how far the process is in a %, the script writes to a session what "state" the process is in, a "total" for the amount it needs to do, and a "progress" to say how much it's done. While that long AJAX call is being made, another separate AJAX call is made to a page that lists those 3 session variables so it can turn it into an accurate progress bar in JavaScript, and it repeats itself every 0.5 seconds or so.
The problem is that in order for that second AJAX call to be able to retrieve the session data, the session has to be closed. So in the length script, it opens the session, writes the data, then closes it.
Is there any significant performance loss caused by doing this? Is there a better alternative to show how far along an lengthy AJAX call is?
EDIT: I should have chosen my words more carefully. The process used to take 30+ seconds, and it felt necessary to show a real progress bar instead of a repeating gif. After changing the algorithm, it now only takes 1-5 seconds on average, but I would guess that it could get up to 10 seconds in extreme cases. It is asynchronous and there is other content on the page, and they must choose to start the process. They can go to other pages or even close the window and come back later to see it finished. Now that the timespan is significantly lower, I'm wondering if I'm hurting its fast performance by trying to show a "true" progress bar or if there's another alternative to do so.