我正在使用CI並嘗試使用Pthreads,並且我在控制器中有一個函數,它將調用線程,並從線程中實例化一個庫的對象,使用新的超過$這個 - >負載>我的線程繼承Thread類,因此不列入允許我做負載庫>庫,所以我用實例化新 這裏是我的控制器類:無法在pthreads中執行CI get_instance()
defined('BASEPATH') OR exit('No direct script access allowed');
include_once APPPATH.'/libraries/feedstart_class.php';
include_once APPPATH.'/libraries/test/thread.php';
class Welcome extends CI_Controller {
public function __construct() {
parent::__construct();
$this->load->library('event_library');
$this->load->model('global_model');
}
public function testThreadCommandLine() {
$mythreads = array();
$ci_obj = & get_instance();
for($i = 0;$i<5;$i++) {
$mythreads[$i] = new MyThread();
$mythreads[$i]->setIndex($i);
$mythreads[$i]->setCI($ci_obj);
$mythreads[$i]->start();
}`enter code here`
}
}
這裏我的螺紋類
include_once APPPATH.'/libraries/common_event_library.php';
Class MyThread extends Thread
{
private $_index;
private $_CI;
public function __construct() {
}
public function setIndex($index) {
$this->_index = $index;
}
public function setCI($ci_obj) {
$this->_CI = $ci_obj;
}
public function getIndex() {
return $this->_index;
}
public function run() {
sleep(rand(0,10));
echo "The index of the object is ".$this->_index;
$common_event_library = new Common_event_library($this->_CI);
$common_event_library->display();//gets all sports categories from our system
echo "<br>";
}
}
這裏是我的庫
Class Common_event_library {
private $_CI;
public function __construct($ci_instance) {
$this->_CI = $ci_instance;
}
public function display() {
$this->_CI->db->select("*");
$this->_CI->db->from("sports_cateogry");
$result = $this->_CI->db->get()->result();
print_r($result);
}
}
當我運行來自瀏覽器和命令行,它說通知的testThreadCommandLine:試圖讓用C非對象的屬性:\ XAMPP \ htdocs中\ CI \應用程序\庫\ common_event_library.php
當我做var_dump($ this - > _ CI)我得到空 –