How to implement thread with database query in Yii 1.x

I have an existing project. Now I want to use multi-threading in my project. But I searched in Google Here is not getting any sufficient information about Yii 1.x thread. Could you please help me. I am unable to get model inside of the ContentThread extension. See my code:

[b]

protected/extensions/threads/ContentThread.php[/b]


class ContentThread extends Thread {

    public $content;


    public function __construct($content) {

       $this->content = $content;

    }




    public function run() {

       foreach ($this->content as $value) {

            $his = new LogHistory();

            $his->user_id = 1000;

            $his->login_date = gmdate('Y-m-d H:i:s');

            $his->logout_date = gmdate('Y-m-d H:i:s');

            $his->ip = '0.0.0.0';

            $his->save();

        }

    }

}

TestController.php -> actionThread()


public function actionThread(){

        Yii::import('ext.threads.ContentThread');            

        $content = array(1,2,3,4,5); /* just for static */

        //echo "<pre>"; print_r($content); echo "</pre>";

        //echo "<pre>"; print_r(array_slice($content, 2)); exit;

        $thread_1 = new ContentThread(array_slice($content, 0, 2));

        $thread_2 = new ContentThread(array_slice($content, 3));


        $thread_1->start();

        $thread_2->start();




    }

Error Output:


Fatal error: Class 'LoginHistory' not found in C:\xampp\htdocs\xxxxx\protected\extensions\threads\ContentThread.php on line 19


Fatal error: Class 'LoginHistory' not found in C:\xampp\htdocs\xxxxx\protected\extensions\threads\ContentThread.php on line 19

See I have posted my coding. Here is Yii model LoginHistory() not working. Because of my class extend from Thread instead of CApplicationComponent. How it will work with Yii context?

did you try and import your model in your extension





public function run() {

Yii::import('path.to.models.LoginHistory');

       foreach ($this->content as $value) {

            $his = new LoginHistory();

            $his->studio_id = 54;

            $his->user_id = 1000;

            $his->login_at = gmdate('Y-m-d H:i:s');

            $his->logout_at = gmdate('Y-m-d H:i:s');

            $his->ip = '0.0.0.0';

            $his->save();

        }

    }



@alrazi This is not only the model related but also other yii context I need All yii context like Yii::app(), CDbExpression, LoginHistory::model(), model, controller, component, extensions , vendor, Yii mail etc. I searched Google since last 8 days. There are no any yii related thread.

Your Yii::import also not working. because ContentThread extends from Thread not CApplicationComponent or CWidget Thats why yii inbuild code not working. how will work in my ContentThread.php file?

Please help…