Home > Backend Development > PHP Tutorial > PHP asynchronous multi-threaded swoole usage example, multi-threaded swoole_PHP tutorial

PHP asynchronous multi-threaded swoole usage example, multi-threaded swoole_PHP tutorial

WBOY
Release: 2016-07-13 10:14:10
Original
1069 people have browsed it

php asynchronous multi-threaded swoole usage example, multi-threaded swoole

The example in this article describes the usage of php asynchronous multi-threaded swoole. Share it with everyone for your reference. The specific analysis is as follows:

swoole redefines the high-performance network communication framework of PHP language and provides asynchronous multi-threaded services of PHP language. The following example can confirm this function.

Generally speaking, Swoole provides asynchronous multi-threaded server in PHP language, asynchronous TCP/UDP network client, asynchronous MySQL, database connection pool, AsyncTask, message queue, millisecond timer, asynchronous file reading and writing, asynchronous DNS query .

I’ve heard of swoole before, it’s an amazing tool to use as a game server... I tried it a little bit today, built an environment under ubuntu and tested it

The specific test code is as follows:

Copy code The code is as follows:
class page extends Controller
{
Function index()
{
$data = createModel('UserInfo')->get(12)->get();
           $this->swoole->tpl->assign('data',$data);
$html = $this->swoole->tpl->fetch('test.html');
$time = $this->showTime();
          return $html.$time;
}
}
shell
ab -c 100 -n 1000 -k http://127.0.0.1/index/

Requests per second
Time per request (mean)
Time per request (mean, across all concurrent requests)

Operation mode:

Swoole EventTCP Swoole SelectTCP Swoole BlockTCP Apache/Prefork
Single process
571.70 [#/sec] 174.916 [ms] 1.749 [ms] 659.01 [#/sec]
151.743 [ms]
1.517 [ms]
561.24 [#/sec]
178.178 [ms]
1.782
80.57
1241.083 [ms]
12.411 [ms]
4 processes
1153.63 [#/sec]
86.683 [ms]
0.867 [ms]
1010.08 [#/sec]
99.002 [ms]
0.990 [ms]
1094.58 [#/sec]
91.359 [ms]
0.914 [ms]

Apache actually has such good efficiency, please save it for future use.

I hope this article will be helpful to everyone’s PHP programming design.

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/911902.htmlTechArticlephp asynchronous multi-threaded swoole usage examples, multi-threaded swoole This example describes the usage of php asynchronous multi-threaded swoole. Share it with everyone for your reference. The specific analysis is as follows: swoole redefines...
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template