PHP and jQuery: Return incremental results as search runs
<p>I need to process a very long running process in PHP (grepping big text files and returning matching lines).  When we run an average query from the command line, the process may take 10-15m.</p>

<p>I wanted to implement in PHP/jQuery, whereby I started the query, then showed incremental results as they came back.</p>

<p>I implemented something close, where I had one ajax call doing the search (worked fine), and had a periodic timer function running calling a second method in the class to get the results.  However, I realized that the 2nd call would really create a new class instance, so the $this->current was different between the main query and the period update timer.</p>

<p>Here's the javascript I was trying (I was kicking it off when clicking a form button):</p>

<pre><code>&lt;script&gt;
  function update_status(data) {
    alert(data);
    jQuery.each(data, function(key, val) {
      if ( key == "progress" )
        $("#progressbar").progressbar({ value: val });
    });
  }
  function progress_setup() {
    setInterval(function() {
      jQuery.ajax({
        type:'POST',
        dataType:'json',
        complete:function(XMLHttpRequest, textStatus){
          update_status(textStatus)
        },
        url:'&lt;?php echo url_for("@grep_status"); ?&gt;'
      })},
      2000);
  }
  function grep(elements) {
    jQuery.ajax({
      type:'POST',
      dataType:'html',
      data:jQuery(elements).serialize(),
      success:function(data, textStatus){jQuery('#results').html(data);},
      beforeSend:function(XMLHttpRequest){progress_setup()},
      url:'/grep'});
  }

&lt;/script&gt;
</code></pre>

<p>But, this doesn't appear to be the right track.  The core issue seems to be:</p>

<ol>
<li>Long running task in PHP</li>
<li>How do you get the status of that task back to a progress bar, and an incremental results dialog?</li>
</ol>

<p>TIA
Mike</p>
