First step: Copy the Workerman to the appropriate location in the thinkphp project (I put it in the root directory, with the thinkphp peer)
Step two: Change all files in Workerman (except the/workerman/lib/constants.php) suffix to. class.php, such as: worker.php change to Worker.class.php
Step Three: Configure the thinkphp namespaces for automatic loading. In the thinkphp configuration file, add the
Array ( ' Workerman ',//modified according to your own location)
Fourth step: Add the Worker module and worker controller to the thinkphp project, or you can name it according to your preference.
NamespaceWorker\Controller;UseWorkerman\Worker;Class Worker{Publicfunction Start(){$worker =New Worker ( text://0.0.0.0:1234 '); //instantiate worker and set protocol, IP and port $worker->count = 4; $worker OnMessage = array ( $this, OnMessage '); //worker other callback methods can refer to OnMessage worker::runall ();} public function onmessage ($connection, $data) {$connection->send (
In the OnMessage method, according to the custom protocol and content format, through the thinkphp A () method to invoke the relevant module, controller, you can do with the normal thinkphp project the same development mode, such as:
$class = A ($data ['/'. $data [' C ']); if (! $class) { $connection->send (else {$action = $data [unset ($data [' m '], $data [' C '], $data [ try {call_user_func_array (catch (throw $ex;}}
Fifth Step: thinkphp entry binding. The entrance binding is the method given by thinkphp3.2.1+, and the previous version has a corresponding method, which can be found on the Internet.
New Portal File worker.php
Define (' App_path ', './application/');
Define (' worker ');d efine ('worker ');d efine ('Start ')//thinkphp other Settings './thinkphp/ Thinkphp.php ';
Finally: Run the worker.php file through the bat file (the Windows environment runs directly with an error)
thinkphp3.2 Integrated Workerman Multi-entry mode (Windows)