CStatePersister question


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?


// state saving

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

$state = $sp->load();

$state['flag'] = $myState;


// 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:


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

if (file_exists($mutexName))


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

// ...