Jump to content

Script execution after timeout


gnznroses

Recommended Posts

I'm trying to figure out how to keep a script executing after it reaches the timeout limit. It has always worked fine on PHP 5.2, but I just updated to PHP 5.4 and now scripts immediately quit executing after the allotted time.

Brief summary of my problem:
I have two pages in my site's admin panel that usually take some time to run. The first crunches some data and displays the results. It sometimes will time out before completing, but if you wait a moment to let it finish in the background and then refresh your browser, it'll display almost immediately, since MySQL has cached the results. A second page has to update a lot of records and sometimes will time out. I need the final output of the script, so after the rows update I log the output to a txt file which I can FTP in and read if need be. This is how things used to work, but now after the upgrade, when the page times out, script execution stops, and for the latter script that means that rows get updated but no log is ever created, which is a problem.

I have tried:

set_time_limit(0);
ignore_user_abort(true);



No effect. I think set_time_limit(0) fails to work because Apache itself times out? Although when the PHP timeout is set to 50, and Apache timeout set to 60, and it seems like execution stops at 50. (We're actually using Litespeed instead of Apache, but it reads the Apache ini file and everything. And we didn't update/change Litespeed when we updated PHP.)

I don't want to raise the Apache timeout beyond 60 for sake of DDoS issues (we've been attacked before). From my understanding there's no way to raise the limit for just one page. I found some things that I thought might do that, for Litespeed, but they had no effect:
In my htaccess file:

RewriteEngine on
RewriteRule ^$ - [E=noconntimeout:1]
RewriteRule ^$ - [E=noabort:1]

Before upgrading PHP I poured over the list of changes on php.net, and never found anything related to this. I've been relying on execution after the timeout for years (for these same two pages), so the sudden change and lack of a solution so far is strange to me. I could attempt to separate some code into chunks and on a cron, but I'd rather not. Any ideas? Thanks!

Edited by gnznroses
Link to comment
Share on other sites

If PHP is timing out then there should be an error logged to that effect. Maybe you don't have your logging set up yet? Or the error_reporting level is too low.

 

Not sure what to say beyond you confirming that it's PHP terminating. set_time_limit() should totally work.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.