no effect on $model()->save() with high load

hi there,

i’ve got a problem with the active record system or the database? :(

$session = session::model()->find("sid=:sid AND end=:end", array(':sid' => $_POST['SESSION'], ':end' => "0"));

		if ($session->sid === $_POST['SESSION'] && $session->plant->login === $_POST['ACCOUNT'])


			$dataset = new dataset;




			if (!dataset::model()->exists('plantID=:plantID AND timeStamp=:timeStamp', array(':plantID' => $session->plant->id, ':timeStamp' => $_POST['TIME'])))

				if ($dataset->save())


					$session->lastActivity = time();

					$session->transmitedDS = $session->transmitedDS + 1;

					if ($session->save())


						$this->answers['O'] = 'data successfully uploaded';

					} else {

						$this->answers['E'] = $session->getErrors();




					$this->answers['E'] = 'it occured a problem while uploading data';


				$this->answers['E'] = "there is already data for this time";



			$this->answers['E'] = "session doesn't belong to your account";

The problem occures when this code is requested to many times simultaneously.

Then sometimes the $session model isn't saved… About 30% of the new datasets (DS) aren't regristered…

hopefully somebody nows a solution, greets

The problem is not obvious to me. You have two "if" conditions outside of the if(save()) call. Did you check if they have problem? What about the first line? Does it always returns a not-null session?

i've got a client program in python for the client side and can define the max of simultaneous connections to the server.

if only one connection at once there's no problem… but with five simultaneous connections in about 30% of theses requests the $session couldn't be saved… and $this->answers['E'] becomes an empty array…

if (!dataset::model()->exists('plantID=:plantID AND timeStamp=:timeStamp', array(':plantID' => $session->plant->id, ':timeStamp' => $_POST['TIME'])))

checks a unique key…

is there any possibility to do that by a cvalidator?


if ($dataset->save())

makes sure that the DS was really transmited into the database

Yes, there is a CUniqueValidator that you may use.

However, for your testing scenario, I think you probably should consider enclosing the uniqueness check and saving inside a transaction. Otherwise it is very likely something will not be saved due to uniqueness constraint.

please have another look at the unique test…

there are two columns that have to be together unique… i didn't find a possibility to tell that the CUniqueValidator class.

another question is: what are transactions? but i going to answer that tomorrow ;)

Then you can't use CUniqueValidator because it uses only one column.

You can put the uniqueness check inside beforeSave() method.

A transaction ensures queries inside it to be atomic. See: