[PHP] limit run time of a function?

2004-02-11 Thread Anthony
I have a function in my application that does a large query on my database.
In certain instances the query will take to long to return and will reach
the max execution time set in PHP.ini.  This is ok though, it's already set
to 90 secs and I don't want it any longer than that.  What I would like is
to have a way that I can time a function.  If the function takes to long to
return data, kill it and follow some other path in my app to let the user
know what's going on.  What I'm trying to avoid is the warning from PHP
saying that the script reached max execution time.  The user gets all
confused and then I get help desk calls.  There has got to be another way.
Any ideas?

- Anthony

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] limit run time of a function?

2004-02-11 Thread Richard Davey
Hello Anthony,

Wednesday, February 11, 2004, 1:43:29 PM, you wrote:

A I have a function in my application that does a large query on my database.
A In certain instances the query will take to long to return and will reach
A the max execution time set in PHP.ini.  This is ok though, it's already set
A to 90 secs and I don't want it any longer than that.  What I would like is
A to have a way that I can time a function.  If the function takes to long to
A return data, kill it and follow some other path in my app to let the user
A know what's going on.  What I'm trying to avoid is the warning from PHP

There may be a more elegant way, but this technique should certainly
work (in theory anyway! you'll have to test it for yourself):

Split your script up, so you have the processing script (i.e. the
one that actually does the query that might time out) and a handler
script.

The user is sent to the handler script (via say a form post, or
however you are doing this) and the handler script calls the
processing script via fsockopen().

Using this function you can specify a time-out value - either you'll
be able to stream the results of your processing script back into the
handler (and just echo them out perhaps? depends what it does) or you
can catch the time out and inform the user accordingly.

I probably made this sound more complicated than it really is :)

-- 
Best regards,
 Richardmailto:[EMAIL PROTECTED]

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php