Function Time Limit

nend

  • When is a theme, no longer what it was when installed?
  • Posts: 165
Function Time Limit
« 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.

Arantor

  • As powerful as possible, as complex as necessary.
  • Posts: 14,278
When we unite against a common enemy that attacks our ethos, it nurtures group solidarity. Trolls are sensational, yes, but we keep everyone honest. | Game Memorial

nend

  • When is a theme, no longer what it was when installed?
  • Posts: 165
Re: Function Time Limit
« Reply #2, on June 3rd, 2012, 04:19 AM »
That is sad, :sob:, you would think there would be a way to do this by now.

Arantor

  • As powerful as possible, as complex as necessary.
  • Posts: 14,278
Re: Function Time Limit
« Reply #3, 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!

Nao

  • Dadman with a boy
  • Posts: 16,082

Arantor

  • As powerful as possible, as complex as necessary.
  • Posts: 14,278
Re: Function Time Limit
« Reply #5, 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.

nend

  • When is a theme, no longer what it was when installed?
  • Posts: 165
Re: Function Time Limit
« Reply #6, on June 4th, 2012, 05:04 PM »
The ext is installed on my cheap account. :niark:

Norodo

  • Oh you Baidu, so randumb. (60 sites being indexed at once? Jeez)
  • Posts: 469

Arantor

  • As powerful as possible, as complex as necessary.
  • Posts: 14,278
Re: Function Time Limit
« Reply #8, on June 4th, 2012, 07:10 PM »
Hrm, in which case it might be worth making the leap to make use of such extras.