Intensive PHP script failing w/ “The timeout specified has expired” error / ap_content_length_filter

后端 未结 10 1198
南方客
南方客 2020-12-30 10:50

Running a MySQL intensive PHP script that is failing. Apache log reports this:

[Wed Jan 13 00:20:10 2010] [error] [client xxx.xx.xxx.xxxx] (70007)
The timeou         


        
10条回答
  •  我在风中等你
    2020-12-30 11:26

    Note: This answer is duplicated verbatim from a similar question.

    Original Answer

    I have Apache 2.4.6, but the patch to fix it is provided in Apache >= 2.4.8. The key here is to start your output immediately so that Apache (mod_proxy_fcgi) thinks the connection is active.

    For example, I am using PHP and the DB query for my AJAX call takes > 30 seconds. Because I know that the overall response will be "Content-Type: application/json", I send that header immediately.

    #1: Start output immediately
    #Note: Sending the header is innocuous
    #   it can be changed later using the $replace parameter
    #   (see #3)
    header( 'Content-Type: application/json' );
    
    #2: Run slow query
    mysql_query( "SELECT * FROM giant_table" );
    
    #3: Change header as needed
    header( 'Content-Type: application/csv', true );
    
    #output content
    

提交回复
热议问题