dongxiangqian1855 2016-02-25 19:57
浏览 33
已采纳

PHP脚本运行完成,但超时

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!

  • 写回答

1条回答 默认 最新

  • 普通网友 2016-02-25 20:06
    关注

    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.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?