Broadly speaking, this sort of activity needs to be treated as “a background job.” The web-page ... Apache-based or otherwise ... therefore should be seen merely as a user interface by which the user can submit work to be processed, query the present status of the work in progress, and retrieve the output. There are many “batch job monitoring systems” out there for all operating systems, including those that are designed to be cross-platform. There are CPAN modules, as well.
An elementary implementation of this idea ... which, by the way, is probably the most common one ... is to have one-or-more workers that are launched by means of cron, with an SQL database acting as the job-queue. The workers query the database to find work-to-do and, using an SQL transaction to provide atomicity, select one. Then they carry out the work, ensuring that any exceptions that may be thrown will be caught. And this they do forever.
A key aspect of this arrangement is that, no matter how many units of work may be requested, and no matter how rapidly they come in, the work is always carried out in a predictable and controlled way. The web page is, and the web page remains, only the user-interface: the means by which the user can interact with the batch system, but not a player in the game.