I'm running Zend server and ZF1 with db2 database. For some export, the queries take a very long time (>50 seconds) this causes a 408 timeout error. I'm looking for a solution to show a loading message on the client while running the SQL query. Any help is appreciated.
You need to increase the maximum execution time allowed for php so that it can finish and not be terminated with 408 return code. Either locally for that script only: http://php.net/manual/en/function.set-time-limit.php or globally: http://php.net/manual/en/info.configuration.php#ini.max-execution-time
The simplest way to show loading progress is to have the long job executed with an AJAX request. Your main page should show the loading progress and fire a request to the export script with Javascript. When that export script finishes, the main page can show a success message.
If the export script creates something like a CSV file that needs to be downloaded, rather than send that CSV as the response body you can output it to a file on the server and then send a url of that file in the response. Your Javascript in the main page can show that url and prompt the user to download it in the success message.
Another way to do it is to build a job queue. This can be done using a queuing system or just using a table of jobs in the database. When the user requests an export, you create a new job. You need a process that runs on the server, as a cron job for example, that checks the table for all new jobs, and when there is one it runs the export and updates the status of the job. In your page you need to periodically, with Javascript or simply by reloading the page, check the status of your job and show a success message when it's completed. Again, if the export creates a file, the server process needs to write it and you include a link to download in the success message.