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?