I'm adding in some functionality to an existing invoicing system, which already is running close to timeout length. Testing the addition by itself, I'm timing out, so I would appreciate some input on how I can restructure my logic to make all of this play nicely.
Here's an overview of the existing system.
1. build-invoice-data.php pulls data from the db and assembles an XML file of invoices. The latest invoice run built a 1.2M file. User proceeds (to preview page).
2. preview-invoices.php reads XML file, generates a tabular preview, and prepares some temp tables in the db. Nothing notable here. User proceeds (signals OK to commit invoice run to db).
3. commit-changes.php merges temp tables into live tables and generates aggregate pdf of all invoices for printing. Here's the start of the problem. I'm feeding the XML file into Apache FOP for the PDF generation and it takes a while to do its job, but this step is completing so far.
The addition would be crammed into commit-changes.php and include extracting individual invoices from the XML and passing them through FOP for a PDF to insert in to the db (blob). This would be done so that actual invoices can be attached to the invoice number allowing quicker access than digging through a file of papers. This is the part that times out even by itself. It's currently a foreach that loops through all the XML invoice nodes, builds mini XMLs, and then feeds them to FOP. My last test was able to generate 20 before the 60-second timer expired.
To eliminate some suggestions in advance, I can't regenerate a duplicate invoice purely from the db after the fact because each invoice run includes state information that changes immediately afterward. Also, I can't easily modify the function of the PDF generation because the XSL template is built for the current XML structure and I would prefer to stay away from my working template.
Am I stuck with just increasing the script timeout value, or does someone more experienced recognize a time saver somewhere? Threads? Ajaxify?
If it helps suggestions, this app is on a Win2k server, PHP5, Apache2, fop 0.93.