I am attempting to redirect creation of an easy Perl script to some internet browser using PHP. The Perl script sometimes take 2-3 hrs to complete and show output towards the screen. By this time around, I suppose Apache Server simply timesout and shows a mistake message discribed above.

This is actually the sample code snipet.

 # 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";

    	$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.

the reason for attempting to run this through the net server? You need to run mtss is a little in a different way. The webserver should signal the perl script to employ a startfile or db entry. A wrapper for that script operates on cron and searches for the startfile. if this sees it, it begins the perl process. The perl proc creates to a different web accessible file. after your internet application signals the perl script to begin, it forwards to some page that ajaxes the creation of perl file every 1 second using settimeout.


Think about using Ajax it's not necessary to have a connection available to the server, but rather you hit it with numerous demands:

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

		function Ajax(){
		var xmlHttp = getXmlHttp();
		xmlHttp.open("GET","session.log?" + Math.random(),true);


Another possibility would be to request your perl script to continuously produce output.

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";
kill 9, $heartbeat_pid;     # clean up child at end of script