Apache Server zaman aşımı hata mesajı ile "sayfa görüntülenemiyor"

2 Cevap php

I'm trying to redirect output of a simple Perl script to a web browser using PHP. The Perl script sometimes take 2-3 hours to execute and show output to the screen. By this time, I guess Apache Server simply timesout and displays an error message discribed above.

İşte örnek kod parçası, mikroişlemciyi olduğunu.

 # The tmpOutput.txt contains output of a Perl script.
 # Read a file using an handle.
$handle = popen("tail -f tmpOutput.txt", 'r');

 # Check if read handle has been allocated properly.
if ($handle) {
    # to prevent the code from hanging up when the response is slow.
    stream_set_blocking($handle, FALSE);

    # Set the stream timeout period to 24 hours i.e. 86400 seconds.
    stream_set_timeout($handle, 86400);

    # Get the available stream meta data information.
    $info = stream_get_meta_data($handle);

    # While there's no end of file, read the file contents and redirect them to standard display.
    while((!feof($handle)) && (!$info['timed_out'])) {
    	$buffer = fgets($handle);
    	echo "$buffer<br/>\n";
    	ob_flush();
    	flush();

    	$info = stream_get_meta_data($handle);
    }

    # Check if some issue while streaming data.
    if ($info['timed_out']) {
    	echo 'Connection timed out!';
    }
}

 # Close the file handle.
pclose($handle);

2 Cevap

neden web sunucusu aracılığıyla bu çalıştırmak için çalışıyoruz? Sen biraz farklı bu çalıştırmanız gerekir. Web sunucusu bir startfile veya db girişini kullanarak başlamak için perl sinyal olmalıdır. Komut için bir sarıcı cron'nun çalışır ve startfile arar. onu gördüğünde, bu perl işlemini başlatır. Perl proc başka bir web erişilebilir dosyaya yazar. web uygulaması başlatmak için perl işaret sonra, her 1 saniye setTimeout kullanarak perl dosyanın çıkışını ajaxes bir sayfaya yönlendirir.

EDIT

Eğer sunucuya açık bir bağlantı tutmak zorunda değilsiniz, ama bunun yerine istekleri ile çok sayıda vurmak Ajax kullanmayı düşünün:

	<script type="text/javascript">
		function getXmlHttp()
		{
					var xmlHttp;
			try{	
				xmlHttp=new XMLHttpRequest();// Firefox, Opera 8.0+, Safari
			}
			catch (e){
				try{
					xmlHttp=new ActiveXObject("Msxml2.XMLHTTP"); // Internet Explorer
				}
				catch (e){
					try{
						xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
					}
					catch (e){
						alert("No AJAX!?");
						return false;
					}
				}
			}
			return xmlHttp;
		}

		function Ajax(){
		var xmlHttp = getXmlHttp();
		xmlHttp.onreadystatechange=function(){
			if(xmlHttp.readyState==4){
				document.getElementById('logwindow').innerHTML=xmlHttp.responseText;					
				setTimeout('Ajax()',1000);
			}
		}
		/* NAME OF OUTPUT FILE HERE */
		xmlHttp.open("GET","session.log?" + Math.random(),true);
		xmlHttp.send(null);
		}


		Ajax();
		</script>

Başka bir olasılık sürekli çıktı üretmek için perl komut için düzenlemektir.

#!/usr/bin/perl
my $heartbeat_pid = fork();
if ($heartbeat_pid == 0) {    # child process to print a newline every 10 minutes
    my $output_freq = 600;
    for (;;) {
        sleep $output_freq;
        print "\n";
    }
}
&the_main_routine_that_takes_a_long_time_to_produce_output();
kill 9, $heartbeat_pid;     # clean up child at end of script