title: Progress bar with PHP & Ajax
body: <p>I am working on progress bar which updates progress using ajax requests and session variables. When my program performs time consuming operation such as sending many emails etc. it just set proper session variable (which contains progress value). This operation is started by function post() in code below. </p>
  
  <p>In the meantime, the second function ask() is performed in loop every 500ms. It should return current progress in real time. And here is the problem: every request sent by ask() are waiting for request sent by post() function is finished. The funny part is that if I set some URL like google.com instead of url/to/progress it works just fine except that it is not what I want :). Which means that problem is on the server side.</p>
  
  <p>Not sure if it's important but I use Yii Framework.</p>
  
  <p>All the code below is only scratch (but working) and its only purpose is to show what I meant.</p>
  
  <p>Thanks in advance.</p>
  
  <p>Sorry for my poor english :)</p>
  
  <p>View part:</p>
  
  <pre><code>&lt;script type="text/javascript"&gt;
  function ask() {
    var d = new Date();
    var time = d.getTime();
    $.ajax({
  
      type: 'get',
      url: '/url/to/progress' + '?time=' + time,
      success: function(data) {
        $("#progress").html(data);
      }
    })
  }
  
  function post() {
    var d = new Date();
    var time = d.getTime();
  
    $.ajax({
        type: 'post',
        url: '/url/to/post' + '?time=' + time,
        data: {"some": "data"},
        success: function(data) {alert(data)}
      });
  }
  
  $("#test").click(
    function() {
      post();
      var progress = setInterval("ask();", 500);
    }
  );
  &lt;/script&gt;
  </code></pre>
  
  <p>Controller part:</p>
  
  <pre><code>public function actionPost($time) {
    sleep(5); // time consuming operation
    echo $time . ' : ' . microtime();
    exit;
  }
  
  public function actionProgress($time) {
    echo $time . ' : ' . microtime();
    exit;
  }
  </code></pre>