serv = new Swoole_server ("0.0.0.0", 9501); $this->serv->set (' worker_num ' = 8, ' daemonize ' and false, ' max_request ' = = 10000, ' dispatch_mode ' = 3, ' Debug_mode ' + 1, ' task_worker_num ' and 8 )); $this->serv->on (' Workerstart ', Array ($this, ' Onworkerstart ')); $this->serv->on (' Connect ', Array ($this, ' onConnect ')); $this->serv->on (' Receive ', Array ($this, ' onreceive ')); $this->serv->on (' Close ', Array ($this, ' onClose ')); Bind callback $this->serv->on (' Task ', Array ($this, ' ontask ')); $this->serv->on (' Finish ', Array ($this, ' onfinish ')); $this->serv->start (); } Public Function Onworkerstart ($serv, $worker _id) {echo "onworkerstart\n"; Determines whether the task worker process if ($worker _id >= $serv->setting[' Worker_num ') {$this->pdo = new PDO ( "Mysql:host=localhost;port=3306;dbname=test", "root", "123456", Array (Pdo::mysql_attr_init_command = "SET NAMES ' UTF8 ';", Pdo::attr_errmode =& Gt Pdo::errmode_exception, pdo::attr_persistent = true)); }} Public Function OnConnect ($serv, $FD, $from _id) {echo "Client {$FD} connect\n"; Public Function OnReceive (Swoole_server $serv, $FD, $from _id, $data) {$sql = array (' sql ' = = ' I Nsert into Test values (PID =?, name =?) ', ' param ' = = Array (0, "' Name '") ), ' fd ' = $FD); $serv->task (Json_encode ($sql)); Public Function OnClose ($serv, $FD, $from _id) {echo "Client {$FD} close connection\n"; The Public Function Ontask ($serv, $task _id, $from _id, $data) {try{$sql =Json_decode ($data, true); $statement = $this->pdo->prepare ($sql [' SQL ']); $statement->execute ($sql [' param ']); $serv->send ($sql [' FD '], "Insert"); return true; } catch (Pdoexception $e) {var_dump ($e); return false; }} Public Function OnFinish ($serv, $task _id, $data) {}}new mysqlpool ();
What about MySQL link here or what if I use the data in thinkphp?
How to quote? include_once 'core/ThinkPHP.php';
can it be used in such a way?
The other point is that the server must use the command line mode when it goes down, how do I open it in Windows?
Reply content:
serv = new Swoole_server ("0.0.0.0", 9501); $this->serv->set (' worker_num ' = 8, ' daemonize ' and false, ' max_request ' = = 10000, ' dispatch_mode ' = 3, ' Debug_mode ' + 1, ' task_worker_num ' and 8 )); $this->serv->on (' Workerstart ', Array ($this, ' Onworkerstart ')); $this->serv->on (' Connect ', Array ($this, ' onConnect ')); $this->serv->on (' Receive ', Array ($this, ' onreceive ')); $this->serv->on (' Close ', Array ($this, ' onClose ')); Bind callback $this->serv->on (' Task ', Array ($this, ' ontask ')); $this->serv->on (' Finish ', Array ($this, ' onfinish ')); $this->serv->start (); } Public Function Onworkerstart ($serv, $worker _id) {echo "onworkerstart\n"; Determines whether the task worker process if ($worker _id >= $serv->setting[' Worker_num ') {$this->pdo = new PDO ( "Mysql:host=localhost;port=3306;dbname=test", "root", "123456", Array (Pdo::mysql_attr_init_command = "SET NAMES ' UTF8 ';", Pdo::attr_errmode =& Gt Pdo::errmode_exception, pdo::attr_persistent = true)); }} Public Function OnConnect ($serv, $FD, $from _id) {echo "Client {$FD} connect\n"; Public Function OnReceive (Swoole_server $serv, $FD, $from _id, $data) {$sql = array (' sql ' = = ' I Nsert into Test values (PID =?, name =?) ', ' param ' = = Array (0, "' Name '") ), ' fd ' = $FD); $serv->task (Json_encode ($sql)); Public Function OnClose ($serv, $FD, $from _id) {echo "Client {$FD} close connection\n"; The Public Function Ontask ($serv, $task _id, $from _id, $data) {try{$sql =Json_decode ($data, true); $statement = $this->pdo->prepare ($sql [' SQL ']); $statement->execute ($sql [' param ']); $serv->send ($sql [' FD '], "Insert"); return true; } catch (Pdoexception $e) {var_dump ($e); return false; }} Public Function OnFinish ($serv, $task _id, $data) {}}new mysqlpool ();
What about MySQL link here or what if I use the data in thinkphp?
How to quote? include_once 'core/ThinkPHP.php';
can it be used in such a way?
The other point is that the server must use the command line mode when it goes down, how do I open it in Windows?
You can use thinkphp. Swoole is a standard PHP extension that can be executed as long as the PHP syntax is met.