Home php教程 PHP开发 PHP asynchronous multi-threaded swoole usage example

PHP asynchronous multi-threaded swoole usage example

Dec 21, 2016 pm 01:39 PM

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.

Swoole has been heard before, and it is an artifact when used as a game server... I experienced it a little today, built an environment under ubuntu, and tested it

The specific test code is as follows:

<?php
class page extends Controller
{
    function index()
    {
        $data = createModel(&#39;UserInfo&#39;)->get(12)->get();
        $this->swoole->tpl->assign(&#39;data&#39;,$data);
        $html = $this->swoole->tpl->fetch(&#39;test.html&#39;);
        $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)
Copy after login

Operation method:

Swoole EventTCP SWOOLECTCP SWOOLE BLOCKP Apache/PreFork
Single Process
571.70 [#/SEC] 174.916 [MS] 1.749 [MS] 659.01 [#/SEC]
151.743 [MS]
[MS]
561.24 [#/sec] 7178.178 [ms]
1.782
80.57
1241.083 [ms]
12.411 [ms]
4 process
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 can actually have such good efficiency, keep a claw. It will be useful in the future.

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

For more articles related to PHP asynchronous multi-threaded swoole usage examples, please pay attention to the PHP Chinese website!


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

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
2 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Repo: How To Revive Teammates
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)