Your Search is in Process
By Randal L. Schwartz
Suppose you've got a search engine attached to a Web-page form that takes a little while to come up with a result. You could just tie up the user's browser with a r-e-a-l-l-y l-o-n-g response time, but most people are into instant gratification, and will probably just abort the query.
It would be nice if you could return a message right away that says "Hey, I'm working on it. Gimme a second." Well, that's actually pretty easy to do with the technique shown in this month's column.
Put simply, the CGI request will be split into two separate paths: The first returns a redirect to a URL that initially says "search in progress...reload this page to check the status." The user sees this page quickly after making the query. The second path actually performs the search in the background. When the search is complete, the page the user is reloading is updated to contain the results of the search.
This keeps the communication between the browser and the server to a minimum. To see if the results are in, the user simply hits reload. Or, on browsers that support client-pull, you can even make it autoreload every five or ten seconds, quitting when the result is complete.
Some would suggest using server-push, but I don't because not all browsers support it, and it ties up communication resources during the calculation time. However, I'm not ruling out that technique entirely -- it depends on the application (and maybe a future column will speak to that).<>