thinkphp3.2 Integrated Workerman Multi-entry mode (Windows)

Source: Internet
Author: User

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)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.