raman Posted May 25, 2009 Share Posted May 25, 2009 I want to put an intermediate message in the browser such that the message would display as long as the PHP procesing is occuring and as soon as it is done, it would be replaced by the output. Here is the outline format of my script. I know it can be done using ob_start and ob_get_contents but donot know how it should be done. <html> bla bla <?php #time consuming job ?> Quote Link to comment Share on other sites More sharing options...
starphp Posted May 25, 2009 Share Posted May 25, 2009 Can use body onLoad <body onload="javascript:removeTheMessage();"> Quote Link to comment Share on other sites More sharing options...
raman Posted May 25, 2009 Author Share Posted May 25, 2009 can you elaborate in detail, saying about ob_start etc ? Quote Link to comment Share on other sites More sharing options...
GingerRobot Posted May 25, 2009 Share Posted May 25, 2009 Yes, you can send data to the browser while php is still executing. If you do this, you cannot then alter the data, however. PHP runs on the server side. Essentially, once the data is gone, it's gone. If you wish to have the text change, you'll want something along the lines of an AJAX request. If you google for some AJAX tutorials, you'll find all that you need. If you just want to add to it, then you can just use the flush function. Quote Link to comment Share on other sites More sharing options...
raman Posted May 25, 2009 Author Share Posted May 25, 2009 Here is my code. I have added $opt, $jobid and $dot to solve my purpose of getting the wait message, however I do not get any output, only the wait message comes after a long time and that too with following error: Fatal error: Maximum execution time of 30 seconds exceeded in /usr/local/apache2/htdocs/lipocalinpred/svmtool1.php on line 118 I think I have added the wait message at the wrong place. Any ideas ? <html> <head><link href="lipo.css" rel="stylesheet" type="text/css" media="all"><script type="text/javascript" src="selctall.jsp"> </script></head> <body onload="javascript:removeTheMessage();"> <br> <table align="center" bgcolor="skyblue" width="60%"><tr> <th align="left"> <img src="calycin2.gif" height="130"></img>             <img src="banner.jpg" height="130"></img>          <img src="icgeb_logo1.jpg" height="130"></img></th></tr></table><table align="left" height="50%"><tr><td> </td></tr><tr><td> </td></tr><tr><td> <div id="main"> <div class="leftnav"> <ul class="listnone"> <li class="first"><a href="lipohome.html">Home</a></li> <li><a href="submit.html">Submit</a></li> <li><a href="algorithm.html">Algorithm</a></li> <li><a href="blast/viroblast.php">BLAST search</a></li> <li><a href="help.html">Help</a></li> <li><a href="team.html">Team</a></li> </ul></div></div> </td></tr></table><br> <DIV STYLE="position:absolute; left:330px; width:200px; height:25px"> <CENTER><FONT SIZE="+2" COLOR="00ff00"></FONT></CENTER> <!-----------------------------PHP script --------------------!> <?php echo "<table align='left' width=650 frame='void' cellspacing=1 cellpadding=3 border=0>"; echo "<tr><td height =20></td></tr>"; ########################### Setting Veriables ############################## $randi=rand(0, 1111111); $opt = (empty($_GET['opt'])) ? '' : $_GET['opt']; $dot = (empty($_GET['dot'])) ? '' : $_GET['dot']; $jobid = (empty($_GET['jobid'])) ? '' : $_GET['jobid']; if (!$jobid) { $jobid = time(); } $seq=$_POST['seq']; $userfile=$_FILES['userfile']['tmp_name']; $hybpred=$_POST['hybpred']; $dpchyb=$_POST['dpchyb']; $pssm=$_POST['pssm']; $pthresh=$_POST['pthresh']; $dpcthresh=$_POST['dpcthresh']; $hybthresh=$_POST['hybthresh']; $seqfile= $randi; ########################### Writing Input Seq into file ######################### $pattern = '/>/'; if (preg_match($pattern,$seq)) { $somecontent=$seq; } else { $somecontent = ">sequence\n".$seq; } $freq=0; // Let's make sure the file exists and is writable first. if (!is_writable("$seqfile")) { if (!$handle = fopen("./junkbin/$seqfile", 'w')) { echo "Cannot open file ($seqfile)"; exit; } // Write $somecontent to our opened file. if (fwrite($handle, $somecontent) === FALSE) { ++$freq; //echo "Cannot write to file ($seqfile)"; exit; } //echo "Success, wrote ($somecontent) to file ($seqfile)"; fclose($handle); } if(!$opt || $opt == 'wait') { $progressdot = "images/progressdot.png"; echo "<p><strong>Your job is being processed "; for($i = 0; $i <= ($dot%12); $i++) { echo "<img src='$progressdot'>"; } echo "</strong></p>"; $dot += 1; echo "<p>Please wait here to watch the progress of your job.</p>"; echo "<p>This page will update itself automatically until search is done.</p>"; echo "<p><a href=submit.html>Back to SVM Prediction</a></p>"; } if(!$opt || $opt == 'wait') { echo "<META HTTP-EQUIV=\"refresh\" content=\"10;URL=svmtool1.php?jobid=$jobid&opt=wait&dot=$dot\">"; echo "<META HTTP-EQUIV=\"expires\" CONTENT=\"now\">"; } $filename='outfile'.$randi.'cp'; while(!file_exists($filename)) {} if(!$opt || $opt == 'wait') { echo "<script LANGUAGE=JavaScript>"; echo "location.replace('svmtool1.php?jobid=$jobid&opt=none')"; echo "</script>"; } ######################## get_svm_results() function call in IF-ESLE ################################# if($seq == '' && $userfile == ''){ echo "<TR><TD><font color='#d11010' size=5><br><p align='center'><blink><b>Warning !</b> </blink><br> Please type/paste either sequence/sequences or upload a sequence file from the browser!!</font></p></TD></TR> "; }elseif($seq == ''){ $file_data= implode("",file($userfile)); $sqfile="junkbin/".$randi; $f=fopen("$sqfile","w"); fwrite($f,$file_data); fclose($f); echo "<TR><TD bgcolor='skyblue' width='100%' Align=middle colspan='3'><font size =5.5 color ='AF250A'><b>PREDICTION RESULT<TD></TR><TR><TD><BR></TD></TR>"; echo "<TR><TD width=30%><font size=4><b>Your Job ID is </TD><TD width=5%>:</TD><TD>$randi</TD></TR>"; get_svm_result($randi,$sqfile,$pthresh,$hybthresh,$dpcthresh,$hybpred,$pssm,$dpchyb); }elseif($userfile == ''){ $sqfile= "junkbin/"."$seqfile"; echo "<TR ><TD bgcolor='skyblue' width='100%' Align=middle colspan='3'><font size =5.5 color='AF250A'><b>PREDICTION RESULT<TD></TR><TR><TD><BR></TD></TR>"; echo "<TR ><TD width=30%><font size=4><b>Your Job ID is </TD><TD width=5%>:</TD><TD>$randi</TD></TR>"; get_svm_result($randi,$sqfile,$pthresh,$hybthresh,$dpcthresh,$hybpred,$pssm,$dpchyb); }else{ echo "<TR><TD><font color='#d11010' size=4><br><br><br><img src='e001.gif'> <blink><br><br><font color='#d11010' size=5>Error !!</blink> either upload file from browser or type/paste your sequence in Text area !</font></TD></TR>"; } ######################## FUNCTION get_svm_result() ############### function get_svm_result($randi,$sqfile,$pthresh,$hybthresh,$dpcthresh,$hybpred,$pssm,$dpchyb){ #====================== Executing system commands ======================# $sqfile="junkbin/".$randi; $outfile="outputs/".'scores'.$randi; $testDetails_out=$randi.'testDetails.out';$testDetails1_out=$randi.'testDetails1.out';$testDetails2_out=$randi.'testDetails2.out'; $outfilecp='outfile'.$randi.'cp'; $outfilecp1='outfile1'.$randi.'cp'; $outfilecp2='outfile2'.$randi.'cp'; $hybmodelfile="finl_models/".'pssm-ssc-model'; $modelfile = "finl_models/".'pssm-model'; $dpchybfile="finl_models/".'dpc-ssc-model'; $dpcscore=$randi.'dpcscore'; $scorefile=$randi.'hybscore'; $pssmscore=$randi.'pssmscore'; $outfile2= 'allseqssc_'.$randi; $outfilea='finlf'.$randi; $outfile3='finlflll'.$randi; $outfile4='svmpat1_'.$randi; $outfile5='ps-ssc'.$randi; $outfile6='dpc-ssc'.$randi; system("cat prefile $seqfile endfile > $yrfile"); echo "<TR><TD width=30%><font size=4><b>Your input seq(s) </TD><TD width=5%>:</TD><TD><a href='$sqfile'>Input file</a></TD>"; $myinput='4pssm'.$randi; system("cp $sqfile /usr/local/apache2/htdocs/lipocalinpred/$myinput"); $dpcinput=$randi.'dpcinput'; system("cp $myinput $dpcinput"); if(!empty($hybpred) || (!empty($dpchyb)) || (!empty($pssm))){ system("sh fasta.sh $myinput"); system("perl lipopred.pl $myinput $randi"); } if(!empty($hybpred) || (!(empty($dpchyb)))){ system("perl ssc-normon.pl $outfile2 $randi"); } if(!empty($pssm)){ # system("perl ssc-norm.pl $outfile2 $randi"); system("./svm_classify $outfile4 $modelfile $pssmscore >> $testDetails_out"); system("perl threshold_check.pl $pssmscore $pthresh > outputs/$outfilecp"); } if(!empty($hybpred)){ system("paste -d '' $outfile4 $outfilea > $outfile5"); system("./svm_classify $outfile5 $hybmodelfile $scorefile >> $testDetails1_out"); system("perl threshold_check.pl $scorefile $hybthresh > outputs/$outfilecp1"); } if(!empty($dpchyb)){ $dpcout=$dpcinput.'_dipep'; system("perl fast_betterdipcom.pl $dpcinput +1"); system("paste -d '' $dpcout $outfilea > $outfile6"); system("./svm_classify $outfile6 $dpchybfile $dpcscore >> $testDetails2_out"); system("perl threshold_check.pl $dpcscore $dpcthresh > outputs/$outfilecp2"); } ############################################################################# $sno=$randi.'sno'; $tmpid=$randi.'tmpid'; $seqid=$randi.'seqid'; $download=$randi.'downld'; system("cat $sqfile |grep '>' |nl> outputs/$seqid"); `perl -pi -e "s/\>//g" outputs/$seqid`; `perl -pi -e "s/^ +//" outputs/$seqid`; `perl -pi -e "s/ /\t/" outputs/$seqid`; `cut -f 1 outputs/$seqid >outputs/$sno`; `cut -f 2 outputs/$seqid >outputs/$tmpid`; `perl -pi -e "s/\cM//g" outputs/$seqid`; # `paste outputs/$seqid outfile outputs/$outfilecp > outputs/$download`; echo "<TR><TD colspan=3><font size=3 color='red'><b><i>Note: </font><font size=3>Higher the SVM score, better is the confidence level of prediction. The confidence can also be taken care by using a high value of 'threshold' at submission page.</b></i></font><br><br></TD>"; # echo "<TR><TD align=center colspan=3><a href=outputs/$download><p align='right'>Download result</a></p>"; echo "<TABLE width='80%' bgcolor='pink' border='1' text='F5F4B1'></tr>"; echo "<tr bgcolor='B70B4D'><td width=20% align=middle><font color ='F6F8CC'><b>S.No.</td><td width=50% align=middle><font color ='F6F8CC'><b>Sequence IDs</td><td width=40% align=middle><font color ='F5F4B1'><b>SVM Score</td><td width=60% align=middle><font color ='F5F4B1'><b>Decision</td></font></tr>"; if(!empty($pssm)){ echo"<tr><td width='50%'><font size=4 color=blue>PSSM model</font></td></tr>"; echo "<tr bgcolor='#FFFFFF' onMouseOver=\"bgr_color(this,'lightyellow')\" onMouseOut=\"bgr_color(this,'#FFFFFF')\">"; echo "<td width=20% align=left>"; system("cat prefile outputs/$sno endfile"); echo "</td><td width=50% align=left>"; system("cat prefile outputs/$tmpid endfile"); echo "</td><td width=40% align=middle>"; system("cat prefile $pssmscore endfile"); echo "</td><td width=40% align=middle>"; system("cat prefile outputs/$outfilecp endfile"); echo"</td></tr>"; } if(!empty($hybpred)){ echo"<tr><td width='50%'><font size=4 color=blue>PSSM+SSC model</font></td></tr>"; echo "<tr bgcolor='#FFFFFF' onMouseOver=\"bgr_color(this,'lightyellow')\" onMouseOut=\"bgr_color(this,'#FFFFFF')\">"; echo "<td width=20% align=left>"; system("cat prefile outputs/$sno endfile"); echo "</td><td width=50% align=left>"; system("cat prefile outputs/$tmpid endfile"); echo "</td><td width=40% align=middle>"; system("cat prefile $scorefile endfile"); echo "</td><td width=40% align=middle>"; system("cat prefile outputs/$outfilecp1 endfile"); echo"</td></tr>"; } if(!empty($dpchyb)){ echo"<tr><td width='50%'><font size=4 color=blue>DPC+SSC model</font></td></tr>"; echo "<tr bgcolor='#FFFFFF' onMouseOver=\"bgr_color(this,'lightyellow')\" onMouseOut=\"bgr_color(this,'#FFFFFF')\">"; echo "<td width=20% align=left>"; system("cat prefile outputs/$sno endfile"); echo "</td><td width=50% align=left>"; system("cat prefile outputs/$tmpid endfile"); echo "</td><td width=40% align=middle>"; system("cat prefile $dpcscore endfile"); echo "</td><td width=40% align=middle>"; system("cat prefile outputs/$outfilecp2 endfile"); echo"</td></tr>"; } echo "<tr><td width=40% align=middle>"; echo "</td></tr></TABLE>"; echo "</DIV></html>"; } ?> Quote Link to comment Share on other sites More sharing options...
GingerRobot Posted May 25, 2009 Share Posted May 25, 2009 1.) Use tags around your code -- you need to put the opening tag before your code, and the closing tag after. You know, kinda like all that HTML you're outputting. 2.) Try narrowing down the problem. No-ones going to sift through that code. 3.) Why don't you try seeing if you can get the output you desire on a separate page, without all the other crap going on. You can use the sleep function to simulate a long process. Quote Link to comment Share on other sites More sharing options...
raman Posted May 25, 2009 Author Share Posted May 25, 2009 Yes when I remove all the stuff involving $opt, $jobid and $dot, I do get the right output. Quote Link to comment Share on other sites More sharing options...
raman Posted May 25, 2009 Author Share Posted May 25, 2009 My code in brief: <html> <head><link href="lipo.css" rel="stylesheet" type="text/css" media="all"><script type="text/javascript" src="selctall.jsp"> </script></head> <body> <br><table><tr><td>bla bla</td></tr></table> <?php echo "<table align='left' width=650 frame='void' cellspacing=1 cellpadding=3 border=0>"; echo "<tr><td height =20></td></tr>"; $variable=$_POST['var']; $opt = (empty($_GET['opt'])) ? '' : $_GET['opt']; $dot = (empty($_GET['dot'])) ? '' : $_GET['dot']; $jobid = (empty($_GET['jobid'])) ? '' : $_GET['jobid']; if (!$jobid) { $jobid = time(); } #some PHP processing if(!$opt || $opt == 'wait') { $progressdot = "images/progressdot.png"; echo "<p><strong>Your job is being processed "; for($i = 0; $i <= ($dot%12); $i++) { echo "<img src='$progressdot'>"; } echo "</strong></p>"; $dot += 1; echo "<p>Please wait here to watch the progress of your job.</p>"; echo "<p>This page will update itself automatically until search is done.</p>"; echo "<p><a href=submit.html>Back to SVM Prediction</a></p>"; } if(!$opt || $opt == 'wait') { echo "<META HTTP-EQUIV=\"refresh\" content=\"10;URL=svmtool1.php?jobid=$jobid&opt=wait&dot=$dot\">"; echo "<META HTTP-EQUIV=\"expires\" CONTENT=\"now\">"; } $filename='outfile'.$randi.'cp'; while(!file_exists($filename)) {} if(!$opt || $opt == 'wait') { echo "<script LANGUAGE=JavaScript>"; echo "location.replace('svmtool1.php?jobid=$jobid&opt=none')"; echo "</script>"; } #Here is the time consuming PHP process in which involves a user-defined function and here output file $filename is generated #PHP time consuming........$filename generated ?> Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.