This article mainly introduces the coroutine database query using Swoole in Laravel5.6. It introduces in detail what Swoole is and the use of Swoole in Laravel5.6. It is of great practical value. Friends who need it can refer to it
What is Swoole
Directly apply the introduction of Swoole's official website: PHP's asynchronous, parallel, high-performance network communication engine, written in pure C language, provides PHP language asynchronous multi-threaded server, asynchronous TCP/UDP network client, asynchronous MySQL, asynchronous Redis, database connection pool, AsyncTask, message queue, millisecond timer, asynchronous file reading and writing, asynchronous DNS query. Swoole has built-in Http/WebSocket server/client and Http2.0 server.
The documentation on Swoole's official website is not rich enough, which is a headache, but most of the problems are explained. If you are interested in Swoole, then check out this Swoole introductory tutorial. Swoole provides many awesome functions such as multi-threading and long connections, which brings PHP to a new level. For details, you can read the introductory tutorial. This article is limited to discussing the combination of Laravel and Swoole.
In order to provide services, Swoole must run in CLI mode. What is CLI mode? If your Swoole business code is written in a file called server.php, then enter php server.php on the command line to open it. This is a headache, because the Laravel framework does not work like this, so how can it be combined with Laravel? That’s right, it’s that simple to customize an Artisan Command.
It is highly recommended to use laravel-s
in your laravel project.
composer require "hhxsv5/laravel-s:~1.0" -vvv
Then, rely on the kuaiapp/db
package, which is used to implement the pseudo-PDO interface of Swoole\Coroutine\MySQL
composer require "kuaiapp/db" -vvv
Givevendor/laravel/framework
patch
cd .//vendor/laravel/framework wget https://gist.githubusercontent.com/xiaohuilam/81ae50c1bc06180bd8e6fcbdaadba86a/raw/529cb96ca9abeed7a35076725b3b5cd8a1e04ff7/git.patch git am < git.patch
Start laravel-s
php artisan laravels start
Now you can test your database query.
The above is the entire content of this article. I hope it will be helpful to everyone's study. For more related content, please pay attention to the PHP Chinese website!
Related recommendations:
How LaravelS accelerates Laravel/Lumen through Swoole
##
The above is the detailed content of How to use Swoole's coroutine database query in Laravel5.6. For more information, please follow other related articles on the PHP Chinese website!