Activerecord Problem (Allowed Memory Size Exhausted)

I have a view with a dropdown field that gets filled

via the listData method.

That is :

$list=CHtml::listData(Customers::model()->findAll($criteria), 'CustomerID', 'CustomerID');

echo $form->dropDownList($model,'CustomerID',$list);

As long as the Customer Table is relatively small, everything works fine.

After a data migration we did , the Customers Table increased ,so now we have 65.000 records.

The above mentioned code doesn’t work anymore.

Insted I get the message :

[i]Fatal error: Allowed memory size of 134217728 bytes exhausted (tried to allocate 81 bytes) in /MyApp/framework/db/CDbCommand.php on line 516


After searching the yii forum and the internet ,

-increasing the memory_limit in php.ini to unlimited (-1)

-setting memory_limit from index.php like


-disabling the yii DEBUG mode

nothing changed.The problem persists.

Somebody , suggested not to use ActiveRecord for big amounts of Data,

but our whole application is built using ActiveRecords.

Although , IMHO , I don’t think it is a server problem.(Apache)

Because when I request the same Data (and more complex) with plain php

the server responds immediately.

So ,is there an alternative way in yii to fill such dropdowns with huge amount of data ?

What else would you suggest ?

Many thanks in advance.

You already got the answer: Don’t use AR to populate that dropdown list.

OK , and what should I use instead ?

Hi make sure check on your main index.php file YII_Debug is true


defined('YII_DEBUG') or define('YII_DEBUG',true);

try DAO :)


Tried that already , but respond time increases dramatically.

Besides , I have to click 5-6 times "Continue Script"

in order to get the list filled.

Then you must have done something terribly, terribly wrong.

Are you sure that a dropdown with 65.000 element is a wise idea?

Also, how is the user supposed to scroll in such a ddown? I’d better use an autocomplete filtered, you can show the first 10 elements and update each characther the user types.

In this scenario you never have to manage more than 10 elements each time, and the user experience is improving.

In such scenarios I use select2 with ajax and paging activated on scroll. I’ve got a separate action to populate the select via ajax.

There are some extensions wrapping the select2 js in a widget.

Thanks a lot to all of you guys.

Finally I accomplished it by using an autocomplete field,

which gets loaded with data , partially.

(Ajax call to an action in controller ,which returns data in JSON format

regarding to a query filtered by the value in autocomplete field)