public function __construct()
{
define('APPLICATION_PATH', dirname(dirname(__DIR__)) . "/application");
define('MYPATH', dirname(APPLICATION_PATH));
$this->application = new Yaf_Application(dirname(APPLICATION_PATH) . "/conf/application.ini");
$this->application->bootstrap();
$config_obj = Yaf_Registry::get("config");
$this->config = $config_obj->database->config->toArray();
$this->Serconfig = $config_obj->DbServer->toArray();
$this->pool_size = isset($this->Serconfig['pool_num']) ? $this->Serconfig['pool_num'] : 20;
$this->isasync = isset($this->Serconfig['async']) ? $this->Serconfig['async'] : true;
$this->multiprocess = isset($this->Serconfig['multiprocess']) ? $this->Serconfig['multiprocess'] : false;
$this->http = new swoole_server("0.0.0.0", $this->Serconfig['port']);
if ($this->isasync) {
$this->http->set(array('worker_num' => 1, 'max_request' => 0, 'daemonize' => true, 'dispatch_mode' => 1, 'log_file' => $this->Serconfig['logfile']));
} else {
$this->http->set(array('worker_num' => 10, 'task_worker_num' => $this->pool_size, 'max_request' => 0, 'daemonize' => true, 'dispatch_mode' => 1, 'log_file' => $this->Serconfig['logfile']));
}
//$this->process = new swoole_process(function($process) use($http) {
/*for ($i = 0; $i < $this->pool_size; $i++) {
$db = new mysqli;
$db->connect($this->config['host'],$this->config['user'],$this->config['pwd'],$this->config['name']);
//设置数据库编码
$db->query("SET NAMES '".$this->config['charset']."'");
$db_sock = swoole_get_mysqli_sock($db);
swoole_event_add($db_sock, array($this, 'onSQLReady'));
$this->idle_pool[] = array(
'mysqli' => $db,
'db_sock' => $db_sock,
'fd' => 0,
);
}*/
// print_r($this->idle_pool);
//print_r($this->taskid);
//$http->sendMessage('zqf \n',0);
//});
//$this->process->start();
//$http->addProcess($this->process);
if ($this->isasync) {
$this->http->on('WorkerStart', array(&$this, 'onStart'));
} else {
$this->http->on('Task', array(&$this, 'onTask'));
$this->http->on('Finish', array(&$this, 'onFinish'));
}
//$http->on('pipeMessage',array($this , 'onpipeMessage'));
$this->http->on('Receive', array(&$this, 'onReceive'));
$this->http->start();
}