CStatePersister question

Hi,

I have console app starting by cron. I want it to have only one copy running simultaneously.

Is the best way to store state flag to use CStatePersister?

Is there way to store state without loading/saving all state information or only like in code below?



<?php


// state saving


$sp = Yii::app()->getStatePersister();


$state = $sp->load();


$state['flag'] = $myState;


$sp->save($state);





// state loading


$state = $sp->load();


$myState = isset($state['flag']) ? $state['flag'] : false;


?>


Maybe there is more pretty way to do such thing?

No need to go this complex way. ;) Just create a temporary file to indicate if a job is running.

Thanks for advise!

I got something like this:



<?php


$mutexName = Yii::app()->runtimePath.'/.mutex';


if (file_exists($mutexName))


	exit();





fclose(fopen($mutexName, 'x'));





// ...





unlink($mutexName);


?>