2011-10-18 7 views
0

私はいくつかのことをチェックしてから、8kbのチャンクにファイルをストリームするダウンロードスクリプトを持っています。print/flush文中にPHPスクリプトのタイムアウトが発生しますか?

転送がどのように見えるんループ:私は非常に遅いダウンロードをシミュレートする小さなアプリケーションを書い


$file = @fopen($file_path,"rb"); 
if ($file) { 
    while(!feof($file)) { 
    set_time_limit(60); 
    print(fread($file, 1024*8)); 
    flush(); 
    if (connection_status()!=0) { 
     @fclose($file); 
     die(); 
    } 
    } 
    @fclose($file); 
} 

。ダウンロードを続ける前に2分間待ちます。私は60秒の時間制限を設定していたので、スクリプトがタイムアウトすることを期待しました。これは起こらず、ダウンロードが完了するまでダウンロードが続けられます。 print/flushで費やされた時間は、スクリプトの実行時間には含まれていないようです。これは正しいです? print/flushコマンドの時間制限を指定できるように、クライアント/ブラウザにファイルを送信するより良い方法はありますか? set_time_limit()から

答えて

1

The set_time_limit() function and the configuration directive max_execution_time 
only affect the execution time of the script itself. Any time spent on activity 
that happens outside the execution of the script such as system calls using system(), 
stream operations, database queries, etc. is not included when determining the 
maximum time that the script has been running. This is not true on Windows where 
the measured time is real. 

あなたはの線に沿って、time()関数の呼び出しと実際の時間の経過を測定することができますいずれかのようなので、それが見えます:

$start = time(); 
while (something) { 
    // do something 
    if(time()-$start > 60) die(); 
} 

それとも、使用することができますWindows。私は最初のオプションを好む:p

+0

これは、スクリプトの実行をブロックするflush文の場合には役に立ちません。それが返ってこない場合、私は時間のチェックをすることができません... – Christo

+0

ちょうど興味のために。私はIISでWindows上でテストを実行しましたが、これは私にとっても死ぬことはありませんでした(これは長いことでしたが、IISはPHPの実行期限ではなく、犯人になると思います)。プロダクションサーバーはLinuxとApacheを実行しています。 – Christo

関連する問題