Forum Moderators: coopster & phranque

Message Too Old, No Replies

How to exit a FastCGI script without stopping the process?

         

MichaelBluejay

10:44 am on Nov 5, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



I'm trying to convert my CGI scripts to FCGI to improve performance since my scripts do a lot of database calls, and FCGI keeps the database connection open. But I understand that if I use the "exit;" command in my script, that closes the connection to the database and the script has to start over again from scratch the next time it's called. That kind of defeats the purpose of using FCGI.

So, how do I do a graceful exit? If I had just one exit test then I could change this:

[b]if ($badData) { exit;}[/b]

to this:

[b]if (!$badData) { 
[long code block]
}[/b]

...but I have a *bunch* of exit tests throughout the script. If I went the above route I'd be nesting DO blocks within DO blocks within DO blocks, and it would be pretty ugly.

What am I missing?

Romeo

2:31 pm on Nov 6, 2006 (gmt 0)

10+ Year Member



Just a hack-around:
you could put an "ExitLabel" at the end of your script and use goto().

Yes, this looks more like FORTRAN-4 than Perl, but it should work nicely without breaking your nested DO block logic.

Kind regards,
R.

MichaelBluejay

12:57 am on Nov 15, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



If I'm afraid with goto & ExitLabel. I tried to research with Google but I couldn't figure out how I would implement it. Can you show me how I would code it?

Romeo

2:45 pm on Nov 16, 2006 (gmt 0)

10+ Year Member



Something like this should work perhaps (untested):

if ($badData) {
goto EXIT;
}
...

EXIT: # last statement, end of script

__END__

Kind regards,
R.

Matt Probert

3:56 pm on Nov 16, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I use a flag, initialy set to zero and tested at apprpriate points:

$bad_data = 0;

while <FILE> &&!bad_data
{

}

For example.

Matt

MichaelBluejay

1:38 am on Nov 17, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Thanks, Romeo. Wow, that's some pretty simple syntax! Worked just fine.