Jump to content

[SOLVED] PHP Timeout solution?


andrewgarn

Recommended Posts

OK some people here might remember me requesting a solution to my update pages timing out. I have attempted solutions but have come to the conclusion it might be the server, which ive found to be horribly unreliable, (from php query and the internal phpmyadmin)

 

THe update pages cycle through a list of users and update them if the last update time isnt today.

 

Well i thought of a possible solution to the problem, could this work, and if so, how?

 

1. Load page

2. page updates first row

3. page refreshes to itself and updates 2nd user

4. repeat no.3 until end of table.

 

5. stop and output results

 

How could i get this to work, is it feasibile? My user table doesnt currently contain an autoincrementing column.

 

The scripts use queries that take data from url file access, and 2 other tables.

 

Would this fix timeout? if it reloaded the page for each user?

 

Thanks, if you dont understand please post a question

Link to comment
Share on other sites

instead of reloading the page for each user you can use the set_time_limit() or max_execution_time() methods. by default your scripts will try to run in 30 seconds then timeout, this wont work if you have a huge database to process obviously.

 

heres an example:

 

set_time_limit(3600); gives your script 3600 seconds to run  :)

Link to comment
Share on other sites

instead of reloading the page for each user you can use the set_time_limit() or max_execution_time() methods. by default your scripts will try to run in 30 seconds then timeout, this wont work if you have a huge database to process obviously.

 

heres an example:

 

set_time_limit(3600); gives your script 3600 seconds to run  :)

 

Sorry i was eating.

 

I tried that previously with set_time_limit(9999); the pages still timed out in 30seconds.

Link to comment
Share on other sites

You can just pass the current row number or whatever row is next to the page through get. If you don't know for sure how to identify the next row, I think something like this will work:

"UPDATE [...] LIMIT 1 OFFSET ".$_GET['currentrow']";
header("Location: ?currentrow=".$_GET['currentrow']++);

 

I think LIMIT and OFFSET work in UPDATE, but I've never tried it. You could so a SELECT subquery if it doesn't.

Link to comment
Share on other sites

Turn error_reporting( E_ALL ) on. Your host may be preventing scripts from executing that function.

 

Had to put a die in a while loop to make the page load but no errors appear from this at the top of php:

 

set_time_limit(999);

error_reporting(E_ALL);

Link to comment
Share on other sites

You can just pass the current row number or whatever row is next to the page through get. If you don't know for sure how to identify the next row, I think something like this will work:

"UPDATE [...] LIMIT 1 OFFSET ".$_GET['currentrow']";
header("Location: ?currentrow=".$_GET['currentrow']++);

 

I think LIMIT and OFFSET work in UPDATE, but I've never tried it. You could so a SELECT subquery if it doesn't.

 

Is there any way to add an auto inc column to a table after its created and has data in it?

 

I'd still like a solution without the refreshing if possible.

Link to comment
Share on other sites

What kind of server are you using? Do you have access to the configuration?

 

www.freehostia.com

 

no access to configuration I dont think, but its the only server I could find with my requirements:

 

url file access, mysql, etc

 

waiting for ad revenue to pay for hosting.

Link to comment
Share on other sites

So the only solution is the refreshing page?

 

That is my guess. You could do more than one per refresh though. Is this a script that users will be executing or just something that needs to be done manually to set things up? If it is the latter, you could set up a server on your own computer and run it from there.

Link to comment
Share on other sites

So the only solution is the refreshing page?

 

That is my guess. You could do more than one per refresh though. Is this a script that users will be executing or just something that needs to be done manually to set things up? If it is the latter, you could set up a server on your own computer and run it from there.

 

Well i have 3 scripts, 2 of them are currently run manually once a day

 

the other needs to be run every hour throughout the day

 

users of the site have no access to these pages.

Link to comment
Share on other sites

Got a techincal support reply from server about set_time_limit()

 

Hello,

 

Thank you for contacting our Technical Support Department.

 

No it's not disabled, but you can't change this value.

 

Best Regards,

James

Ha! That is such a great answer.

 

So you either have to make your scripts take less than 30 seconds or execute them from a different place. I would recommend setting up a server and doing the two that are manually done on your own server where you can set the timeout.

Link to comment
Share on other sites

Got a techincal support reply from server about set_time_limit()

 

Hello,

 

Thank you for contacting our Technical Support Department.

 

No it's not disabled, but you can't change this value.

 

Best Regards,

James

Ha! That is such a great answer.

 

So you either have to make your scripts take less than 30 seconds or execute them from a different place. I would recommend setting up a server and doing the two that are manually done on your own server where you can set the timeout.

 

Unfortunately the mysql server being used is internal to the server, and cant be accessed from outside, so i'm stuck with the server.

 

I made a new post about the refreshing solution

Link to comment
Share on other sites

I had a problem similiar to yours once. My solution was to create an external file with a list of mysql queries that needed to be executed. Then I read that file line by line and as each one was completed, I removed that line and resaved the file. That way, if the script does timeout. The next time it is run, it continues working on the same project without replicating work.

Link to comment
Share on other sites

I had a problem similiar to yours once. My solution was to create an external file with a list of mysql queries that needed to be executed. Then I read that file line by line and as each one was completed, I removed that line and resaved the file. That way, if the script does timeout. The next time it is run, it continues working on the same project without replicating work.

 

Not sure that would work for me, these pages need to be run every day, and should be automatic without my help if possible

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.