Wedge

Public area => The Pub => Off-topic => Topic started by: nend on May 29th, 2012, 06:11 AM

Title: Function Time Limit
Post by: nend on May 29th, 2012, 06:11 AM
I was wondering is there any way in PHP to set a time limit on a PHP function. Say if the function is not done in a certain amount of time the function execution is cancelled and the function returns nothing.

What I want to do is start a heavy query and if the query doesn't finish in a certain amount of time have the query stop and the function exited.
Title: Re: Function Time Limit
Post by: Arantor on May 29th, 2012, 11:04 AM
No, there isn't.
Title: Re: Function Time Limit
Post by: nend on June 3rd, 2012, 04:19 AM
That is sad, :sob:, you would think there would be a way to do this by now.
Title: Re: Function Time Limit
Post by: Arantor on June 3rd, 2012, 04:22 AM
That concept only really works if the setup is properly geared for asynchronous behaviour, something PHP isn't.

That said, the MySQLi driver (note, not the ext/mysql driver that SMF and Wedge rely on) can actually set a timeout with the mysqli_options() function but you can't intermix them.

That might be enough reason to convince us to move to ext/mysqli though!
Title: Re: Function Time Limit
Post by: Nao on June 3rd, 2012, 10:53 PM
If it makes you feel better... :P
Title: Re: Function Time Limit
Post by: Arantor on June 3rd, 2012, 10:57 PM
I said *might*. It's not really a *huge* change from my perspective, MySQLi can be used mostly as a drop-in replacement over MySQL's original driver, but I'm not sure how widely deployed MySQLi is.
Title: Re: Function Time Limit
Post by: nend on June 4th, 2012, 05:04 PM
The ext is installed on my cheap account. :niark:
Title: Re: Function Time Limit
Post by: Norodo on June 4th, 2012, 07:05 PM
Yeah mysqli is pretty much everywhere
Title: Re: Function Time Limit
Post by: Arantor on June 4th, 2012, 07:10 PM
Hrm, in which case it might be worth making the leap to make use of such extras.