How to use workererman in Thinkphp5.1
Workerman is an open source, high-performance asynchronous PHP socket framework developed purely in PHP. ThinkPHP is a fast, compatible and simple lightweight domestic PHP development framework. This article will introduce to you how to use workererman in Thinkphp5.1.
I have been using swoole before, and recently I studied workerman, so I installed composer
1 |
|
Write a test code in the Thinkphp controller
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
|
Command line execution: php index.php workerman/index. I thought it was done, but the following prompt was reported:
Obviously, Workerman cannot directly run the file. According to the official document, use
php index .php start
php index.php stop
php index.php restart
is executed in this format. So I modified the index.php file to bind the route
1 2 3 4 5 6 7 8 9 10 |
|
and ran php index.php start directly. Unfortunately, it was prompted that the start model could not be found. Why is tp5 parsing start as a route. What should I do? Workerman needs to be executed using the start method, but tp5 needs to parse the parameters into a model.
After checking the information, I found that Thinkphp5.1 itself integrated workererman. You can use thinkphp5 to install workererman, then you can run it using thinkphp's running mode.
The execution command is changed to:
1 |
|
Later, I found that the workerman package integrated by Thinkphp5.1 is a bit troublesome and difficult to use, and if you want to use the workerman service such as PHPSocketIO, use the integrated method Very troublesome.
workerman uses the first parameter as the command to operate the service. Can I change it to use the second parameter as the command to operate the service?
That’s exactly what happened. Find the parseCommand() function in the workerman plug-in. This ghost function is to get the operation command, change:
argv[1] to argv[2], argv[2] to argv[2], change argv[2] to argv[3 ]
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
|
The execution command is changed to
1 |
|
(the first parameter is used for Thinkphp to parse the routing, and the second parameter is used for the workerman to parse the operation service command)
For more workerman knowledge, please pay attention to the tutorial column of the PHP Chinese website workerman Framework.
The above is the detailed content of How to use workererman in Thinkphp5.1. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



To run the ThinkPHP project, you need to: install Composer; use Composer to create the project; enter the project directory and execute php bin/console serve; visit http://localhost:8000 to view the welcome page.

To implement file upload and download in Workerman documents, specific code examples are required. Introduction: Workerman is a high-performance PHP asynchronous network communication framework that is simple, efficient, and easy to use. In actual development, file uploading and downloading are common functional requirements. This article will introduce how to use the Workerman framework to implement file uploading and downloading, and give specific code examples. 1. File upload: File upload refers to the operation of transferring files on the local computer to the server. The following is used

ThinkPHP has multiple versions designed for different PHP versions. Major versions include 3.2, 5.0, 5.1, and 6.0, while minor versions are used to fix bugs and provide new features. The latest stable version is ThinkPHP 6.0.16. When choosing a version, consider the PHP version, feature requirements, and community support. It is recommended to use the latest stable version for best performance and support.

Steps to run ThinkPHP Framework locally: Download and unzip ThinkPHP Framework to a local directory. Create a virtual host (optional) pointing to the ThinkPHP root directory. Configure database connection parameters. Start the web server. Initialize the ThinkPHP application. Access the ThinkPHP application URL and run it.

Performance comparison of Laravel and ThinkPHP frameworks: ThinkPHP generally performs better than Laravel, focusing on optimization and caching. Laravel performs well, but for complex applications, ThinkPHP may be a better fit.

"Development Suggestions: How to Use the ThinkPHP Framework to Implement Asynchronous Tasks" With the rapid development of Internet technology, Web applications have increasingly higher requirements for handling a large number of concurrent requests and complex business logic. In order to improve system performance and user experience, developers often consider using asynchronous tasks to perform some time-consuming operations, such as sending emails, processing file uploads, generating reports, etc. In the field of PHP, the ThinkPHP framework, as a popular development framework, provides some convenient ways to implement asynchronous tasks.

Introduction to how to implement the basic usage of Workerman documents: Workerman is a high-performance PHP development framework that can help developers easily build high-concurrency network applications. This article will introduce the basic usage of Workerman, including installation and configuration, creating services and listening ports, handling client requests, etc. And give corresponding code examples. 1. Install and configure Workerman. Enter the following command on the command line to install Workerman: c

Swoole and Workerman are both high-performance PHP server frameworks. Known for its asynchronous processing, excellent performance, and scalability, Swoole is suitable for projects that need to handle a large number of concurrent requests and high throughput. Workerman offers the flexibility of both asynchronous and synchronous modes, with an intuitive API that is better suited for ease of use and projects that handle lower concurrency volumes.
