in reply to Complete part of a cgi script before the rest

Output the HTML, then deamonize.

Since you mentioned Excel, you might be on Windows. The same idea applies, but the execution is different. Output the HTML, the spawn off a child to do the background work. system(-1, ...) is an easy way to launch a background process in Windows.

Update: Oops, you might be on Windows! Added second paragraph.

Replies are listed 'Best First'.
Re^2: Complete part of a cgi script before the rest
by e5z8652 (Novice) on Apr 15, 2010 at 17:14 UTC

    Oh that was ridiculously easy.

    I did have to fix an error in my script above.

    If you look, you'll see that I execute my query in the line just before the HTML is generated. So at first when I added the daemonize call just after the HTML closed I was still getting the long delays.

    Once I moved all of the MySQL stuff into the same area (below the HTML) it worked perfectly.

    Just one more reason to use subroutines to keep my code clean. I kill myself with messy code. :(

      Just a thought. You may want to consider having the CGI process just queue a request to a daemon to prevent your server/database being overloaded by multiple simultaneous requests. You would simply do an insert into a request queue table with any necessary parameters, and have the daemon periodically check for new requests.

        Right. And if you use a cron job to run a simple script as often as required, you don't even have to write a daemon.

        Alexander

        --
        Today I will gladly share my knowledge and experience, for there are no sweeter words than "I told you so". ;-)
Re^2: Complete part of a cgi script before the rest
by e5z8652 (Novice) on Apr 15, 2010 at 16:07 UTC

    OK, thanks. I'll experiment with this -- I've got another project going that is using an infinite while loop to read a serial port and dump data to MySQL. That works well, but I think this solution would be perfect for that script as well.

    Actually the server is Linux, but the clients have Windows desktops -- hence the Excel files. Excel can open csv, but I need to eliminate any potential confusion.