jldavis76
jldavis76

Reputation: 822

PHP script runs to completion, but is timing out

I have a PHP script which contains many database queries, and copies several database tables, and as such, it takes quite a long time to complete. The problem I am getting, is that it is timing out. However, it appears to be completed, which is what is confusing.

The script is suppose to redirect to view once completed. However, even after extending the time limit to 5 minutes, it gives me the timing out error page. However, when I check the database, all of the tables have been copied completely, indicating that the script was completed.

Am I missing something easy here? Is there a general reason it would time out as opposed to redirecting to the view? I would post some of the code, but the entire script is approximately 1000 lines of code, so it seems a bit extensive to show here.

Also, I am using CodeIgniter.

Thanks in advance for your help!

Upvotes: 1

Views: 229

Answers (1)

Scott Saunders
Scott Saunders

Reputation: 30414

It's possible that the PHP script is not timing out, but the browser you're using has given up waiting for any result. If thats the case you'll need to handle the whole thing differently. For example, run the script in the background and report periodic updates via AJAX or something.

Think of it this way:

  1. Your browser asks your server for a web page and waits for the results.

  2. Your server runs your PHP script, which then asks MySQL to run a query, and waits for results.

  3. MySQL runs the query and returns a result to PHP.

  4. PHP does some more processing and returns a result to the browser.

At step 3, PHP may have timed out and is no longer there. MySQL didn't know that while it was working, it just did its job and then handed a result back to nothing.

At step 4, the browser may have timed out and dropped the connection. PHP wouldn't know that, so it did its job and then returned a result to nothing.

It's two separate timeouts in this example, but your query was completed either way.

Upvotes: 2

Related Questions