Yii Framework Forum: Allowed Memory Size Exhausted - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

Allowed Memory Size Exhausted Rate Topic: -----

#1 User is offline   martijnjonkers 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 43
  • Joined: 07-June 13

Posted 20 September 2013 - 04:58 AM

Hi,

I have a database table and created a model for it using gii:
/**
 * This is the model class for table "Subscriptions".
 *
 * The followings are the available columns in table 'Subscriptions':
 * @property integer $ID
 * @property integer $ModuleID
 * @property integer $AfdelingID
 * @property string $SignUpDate
 * @property string $StartDate
 * @property string $CancelDate
 * @property string $EndDate
 * @property integer $State
 *
 * The followings are the available model relations:
 * @property Afdelingen $afdeling
 * @property Detectoren $module
 */
class TestSubscription extends CActiveRecord
{
	/**
	 * @return string the associated database table name
	 */
	public function tableName()
	{
		return 'Subscriptions';
	}

	/**
	 * @return array validation rules for model attributes.
	 */
	public function rules()
	{
		// NOTE: you should only define rules for those attributes that
		// will receive user inputs.
		return array(
			array('AfdelingID, SignUpDate, State', 'required'),
			array('ModuleID, AfdelingID, State', 'numerical', 'integerOnly'=>true),
			array('StartDate, CancelDate, EndDate', 'safe'),
			// The following rule is used by search().
			// @todo Please remove those attributes that should not be searched.
			array('ID, ModuleID, AfdelingID, SignUpDate, StartDate, CancelDate, EndDate, State', 'safe', 'on'=>'search'),
		);
	}

	/**
	 * @return array relational rules.
	 */
	public function relations()
	{
		// NOTE: you may need to adjust the relation name and the related
		// class name for the relations automatically generated below.
		return array(
			'afdeling' => array(self::BELONGS_TO, 'Afdelingen', 'AfdelingID'),
			'module' => array(self::BELONGS_TO, 'Detectoren', 'ModuleID'),
		);
	}

	/**
	 * @return array customized attribute labels (name=>label)
	 */
	public function attributeLabels()
	{
		return array(
			'ID' => 'ID',
			'ModuleID' => 'Module',
			'AfdelingID' => 'Afdeling',
			'SignUpDate' => 'Sign Up Date',
			'StartDate' => 'Start Date',
			'CancelDate' => 'Cancel Date',
			'EndDate' => 'End Date',
			'State' => 'State',
		);
	}

	/**
	 * Retrieves a list of models based on the current search/filter conditions.
	 *
	 * Typical usecase:
	 * - Initialize the model fields with values from filter form.
	 * - Execute this method to get CActiveDataProvider instance which will filter
	 * models according to data in model fields.
	 * - Pass data provider to CGridView, CListView or any similar widget.
	 *
	 * @return CActiveDataProvider the data provider that can return the models
	 * based on the search/filter conditions.
	 */
	public function search()
	{
		// @todo Please modify the following code to remove attributes that should not be searched.

		$criteria=new CDbCriteria;

		$criteria->compare('ID',$this->ID);
		$criteria->compare('ModuleID',$this->ModuleID);
		$criteria->compare('AfdelingID',$this->AfdelingID);
		$criteria->compare('SignUpDate',$this->SignUpDate,true);
		$criteria->compare('StartDate',$this->StartDate,true);
		$criteria->compare('CancelDate',$this->CancelDate,true);
		$criteria->compare('EndDate',$this->EndDate,true);
		$criteria->compare('State',$this->State);

		return new CActiveDataProvider($this, array(
			'criteria'=>$criteria,
		));
	}

	/**
	 * Returns the static model of the specified AR class.
	 * Please note that you should have this exact method in all your CActiveRecord descendants!
	 * @param string $className active record class name.
	 * @return TestSubscription the static model class
	 */
	public static function model($className=__CLASS__)
	{
		return parent::model($className);
	}
}


I build a super basic unit test:
class SubscriptionTest extends CTestCase
{
    function testCreate()
    {
        echo "This is a test\n";

        $subscription= new TestSubscription();

        echo "Done\n";

        $this->assertTrue( true );
    }
}


but when i run it in cmd using "PHPUnit ./unit/SubscriptionTest.php" i get the following result:
PHPUnit 3.7.21 by Sebastian Bergmann.

Configuration read from C:\xampp\htdocs\cabletracks.com\protected\tests\phpunit.xml

This is a test

Fatal error: Allowed memory size of 134217728 bytes exhausted (tried to allocate 36 bytes) in C:\xampp\htdocs\cabletracks.com\framework\caching\CMemCache.php on line 116


I did not change anything in the model, it is straight from gii.
When i use any other model i created this way i have no problem at all, only with this model.

Anyone got an idea what this could be?

thanks!
0

#2 User is offline   Ankit Modi 

  • Master Member
  • PipPipPipPip
  • Yii
  • Group: Members
  • Posts: 907
  • Joined: 19-February 13
  • Location:India

Posted 20 September 2013 - 05:04 AM

can you post the admin grid code?
may be this issue some data will be more then in filed (memory size of 134217728 by) so it's display not so in admin grid view just remove the filter field on AfdelingID
Thanks,
Ankit Modi
Skype : amodi06
0

#3 User is offline   martijnjonkers 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 43
  • Joined: 07-June 13

Posted 20 September 2013 - 05:17 AM

View PostMaggie Q(Ankit Modi), on 20 September 2013 - 05:04 AM, said:

can you post the admin grid code?
may be this issue some data will be more then in filed (memory size of 134217728 by) so it's display not so in admin grid view just remove the filter field on AfdelingID


I'm sorry i do not understand what you mean, but here is the admin grid code (It is straight from gii)

$this->widget('zii.widgets.grid.CGridView', array(
	'id'=>'test-subscription-grid',
	'dataProvider'=>$model->search(),
	'filter'=>$model,
	'columns'=>array(
		'ID',
		'ModuleID',
		'AfdelingID',
		'SignUpDate',
		'StartDate',
		'CancelDate',
		/*
		'EndDate',
		'State',
		*/
		array(
			'class'=>'CButtonColumn',
		),
	),
));


On the web page it just works all fine, but i cannot create test for it.
0

#4 User is offline   Ankit Modi 

  • Master Member
  • PipPipPipPip
  • Yii
  • Group: Members
  • Posts: 907
  • Joined: 19-February 13
  • Location:India

Posted 20 September 2013 - 05:39 AM

View Postmartijnjonkers, on 20 September 2013 - 05:17 AM, said:

I'm sorry i do not understand what you mean, but here is the admin grid code (It is straight from gii)

$this->widget('zii.widgets.grid.CGridView', array(
	'id'=>'test-subscription-grid',
	'dataProvider'=>$model->search(),
	'filter'=>$model,
	'columns'=>array(
		'ID',
		'ModuleID',
		'AfdelingID',
		'SignUpDate',
		'StartDate',
		'CancelDate',
		/*
		'EndDate',
		'State',
		*/
		array(
			'class'=>'CButtonColumn',
		),
	),
));


On the web page it just works all fine, but i cannot create test for it.




Hey sorry can you post the _form.php code ?
Thanks,
Ankit Modi
Skype : amodi06
0

#5 User is offline   Ankit Modi 

  • Master Member
  • PipPipPipPip
  • Yii
  • Group: Members
  • Posts: 907
  • Joined: 19-February 13
  • Location:India

Posted 20 September 2013 - 05:50 AM

In _form.php find
<label><?php echo GxHtml::encode($model->getRelationLabel


just commnet the line it's solved
Thanks,
Ankit Modi
Skype : amodi06
0

#6 User is offline   martijnjonkers 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 43
  • Joined: 07-June 13

Posted 20 September 2013 - 06:07 AM

View PostMaggie Q(Ankit Modi), on 20 September 2013 - 05:50 AM, said:

In _form.php find
<label><?php echo GxHtml::encode($model->getRelationLabel


just commnet the line it's solved


But i did not have the _form form file. I created it becasue you asked for the code, I have a problem during testing of my model. not on the actual web page itself
0

#7 User is offline   Ankit Modi 

  • Master Member
  • PipPipPipPip
  • Yii
  • Group: Members
  • Posts: 907
  • Joined: 19-February 13
  • Location:India

Posted 20 September 2013 - 06:12 AM

View Postmartijnjonkers, on 20 September 2013 - 06:07 AM, said:

But i did not have the _form form file. I created it becasue you asked for the code, I have a problem during testing of my model. not on the actual web page itself



ok please see it.
forum

stackeverflow

i hope it's some help.
Thanks,
Ankit Modi
Skype : amodi06
0

#8 User is offline   martijnjonkers 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 43
  • Joined: 07-June 13

Posted 20 September 2013 - 06:24 AM

View PostMaggie Q(Ankit Modi), on 20 September 2013 - 06:12 AM, said:

ok please see it.
forum

stackeverflow

i hope it's some help.


Hmm.. actually i already saw those pages and tried what they said... no luck. And they have problems with their complete site. I only have this problem with one model.
0

#9 User is offline   martijnjonkers 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 43
  • Joined: 07-June 13

Posted 20 September 2013 - 06:37 AM

I removed CActiveRecord and now it does not crash...
class TestSubscription //extends CActiveRecord


does this mean this is a yii bug?

Is there maybe way to see memory usage?
0

#10 User is offline   martijnjonkers 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 43
  • Joined: 07-June 13

Posted 20 September 2013 - 08:35 AM

Found it! :D

I use 2 version of the database. A test version and a released version.
I choose wich one to use by checking YII_DEBUG.
In my test i use the same config as the main, but apperently the YII_DEBUG is set to false during a test, so i was talking to the wrong datase.
I checked index-test.php and the YII_DEBUG was set to true, so i do not really get that yet.

But the error occured because the table did not exist in the released database and all the other tables did.
PHPUinit does not show this so i went to investigate and came to this part:

$this->_statement->execute();

wich is in is part of the CDBCommand. this generated the error. I placed a try catch around it and echoed the exeption. this gave me the exact error : could not find table in database X. and database X was the wrong database.

I changed my config/test.php to use the right database and .... voila! succesfull test...

So, one last question. Does anyone know why YII_DEBUG is false when using PHPUnit?
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users