Long Polling That Works But Controller "delayed"

Hello !

I just implemented some long polling inside yii (please see code below)

I can see in the console that the controller is called over and over, which is fine BUT

on the mysql table when a new record shows up,

the controller return results after several calls/replies, when its ok on the mysql side…

It should return result on first call as its querying the db…

same when it updates the table

Is there some kind of caching inside controllers by default or am i missing something obvious (did not set any filters for that purpose)

Ps : using statuscode 200 as Success and Ajaxsuccess not working

Thank you very much (Sorry for the english, i’m French…)

js inside the view that launch script


(function poll(){

    $.ajax({ 

	url: "<?php echo $this->createUrl('message/pool') ?>" ,

    data: {

        user: 'david',

		

    },

	

	Success: function(data){

        alert('success');

    },


	statusCode: {

    200: function(data) {

		

      console.log( data );

	  

	  if (data[0])

	  {

	  	

	  $("#new_mail").effect("pulsate", { times:5 }, 2000);	

		

	  } else {

	  

	  $("#new_mail").stop();

	  

	  }

	  

    }

	}

	,

	dataType: "json",

	

	complete: poll,

	

	timeout: 30000 });

	

})();

Controller :


public function actionPool()

	{

		unset($project_data);

	

		$project_data = Yii::app()->db->createCommand()

    	->select('*')

    	->from('message')

		->where('to_user=:user and is_new=1', array(':user'=>$_GET['user']))

    	->queryAll();

		

		if(!is_null($project_data)) { 

		$sql = "UPDATE message

                        SET is_new = '0'

                        WHERE to_user = '".$_GET['user']."'";

            $command = Yii::app()->db->createCommand($sql);

            $command->execute();

	  	}

		

	  header('Content-type: application/json');	

	  echo CJSON::encode($project_data);	


	}