<h2 align=center>
<img width="200" height="120" alt="Swoole Logo" src="docs/swoole-logo.svg" /> <br />
Swoole is an event-driven, asynchronous, coroutine-based concurrency library with high performance for PHP.
</h2>
[![lib-swoole](https://github.com/swoole/swoole-src/workflows/lib-swoole/badge.svg)](https://github.com/swoole/swoole-src/actions?query=workflow%3Alib-swoole)
[![ext-swoole](https://github.com/swoole/swoole-src/workflows/ext-swoole/badge.svg)](https://github.com/swoole/swoole-src/actions?query=workflow%3Aext-swoole)
[![test-linux](https://github.com/swoole/swoole-src/workflows/test-linux/badge.svg)](https://github.com/swoole/swoole-src/actions?query=workflow%3Atest-linux)
[![Frameworks Tests](https://github.com/swoole/swoole-src/actions/workflows/framework.yml/badge.svg)](https://github.com/swoole/swoole-src/actions/workflows/framework.yml)
[![codecov](https://codecov.io/gh/swoole/swoole-src/branch/master/graph/badge.svg)](https://codecov.io/gh/swoole/swoole-src)
[![Twitter](https://badgen.net/badge/icon/twitter?icon=twitter&label)](https://twitter.com/phpswoole)
[![Discord](https://badgen.net/badge/icon/discord?icon=discord&label)](https://discord.swoole.dev)
[![Latest Release](https://img.shields.io/github/release/swoole/swoole-src.svg)](https://github.com/swoole/swoole-src/releases/)
[![License](https://badgen.net/github/license/swoole/swoole-src)](https://github.com/swoole/swoole-src/blob/master/LICENSE)
[![Coverity Scan Build Status](https://scan.coverity.com/projects/11654/badge.svg)](https://scan.coverity.com/projects/swoole-swoole-src)
## âï¸ Quick Start
Run Swoole program by [Docker](https://github.com/swoole/docker-swoole)
```bash
docker run --rm phpswoole/swoole "php --ri swoole"
```
> For details on how to use it, see: [How to Use This Image](https://github.com/swoole/docker-swoole#how-to-use-this-image).
### HTTP Service
```php
$http = new Swoole\Http\Server('127.0.0.1', 9501);
$http->set(['hook_flags' => SWOOLE_HOOK_ALL]);
$http->on('request', function ($request, $response) {
$result = [];
Co::join([
go(function () use (&$result) {
$result['google'] = file_get_contents("https://www.google.com/");
}),
go(function () use (&$result) {
$result['taobao'] = file_get_contents("https://www.taobao.com/");
})
]);
$response->end(json_encode($result));
});
$http->start();
```
### Concurrency
```php
Co\run(function() {
Co\go(function() {
while(1) {
sleep(1);
$fp = stream_socket_client("tcp://127.0.0.1:8000", $errno, $errstr, 30);
echo fread($fp, 8192), PHP_EOL;
}
});
Co\go(function() {
$fp = stream_socket_server("tcp://0.0.0.0:8000", $errno, $errstr, STREAM_SERVER_BIND | STREAM_SERVER_LISTEN);
while(1) {
$conn = stream_socket_accept($fp);
fwrite($conn, 'The local time is ' . date('n/j/Y g:i a'));
}
});
Co\go(function() {
$redis = new Redis();
$redis->connect('127.0.0.1', 6379);
while(true) {
$redis->subscribe(['test'], function ($instance, $channelName, $message) {
echo 'New redis message: '.$channelName, "==>", $message, PHP_EOL;
});
}
});
Co\go(function() {
$redis = new Redis();
$redis->connect('127.0.0.1', 6379);
$count = 0;
while(true) {
sleep(2);
$redis->publish('test','hello, world, count='.$count++);
}
});
});
```
## Runtime Hook
**Swoole hooks the blocking io function of PHP at the `bottom layer` and `automatically` converts it to a non-blocking function, so that these functions can be called concurrently in coroutines.**
### Supported extension/functions
* `ext-curl` (Support `symfony` and `guzzle`)
* `ext-redis`
* `ext-mysqli`
* `ext-pdo_mysql`
* `ext-pdo_pgsql`
* `ext-pdo_sqlite`
* `ext-pdo_oracle`
* `ext-pdo_odbc`
* `stream functions` (e.g. `stream_socket_client`/`stream_socket_server`), Supports `TCP`/`UDP`/`UDG`/`Unix`/`SSL/TLS`/`FileSystem API`/`Pipe`
* `ext-sockets`
* `ext-soap`
* `sleep`/`usleep`/`time_sleep_until`
* `proc_open`
* `gethostbyname`/`shell_exec`/`exec`
* `fread`/`fopen`/`fsockopen`/`fwrite`/`flock`
## ð Develop & Discussion
+ __IDE Helper & API__: <https://github.com/swoole/ide-helper>
+ __Twitter__: <https://twitter.com/phpswoole>
+ __Discord__: <https://discord.swoole.dev>
+ __ä¸æææ¡£__: <https://wiki.swoole.com>
+ __ä¸æ社åº__: <https://wiki.swoole.com/#/other/discussion>
## ð Awesome Swoole
Project [Awesome Swoole](https://github.com/swoole/awesome-swoole) maintains a curated list of awesome things related to Swoole, including
* Swoole-based frameworks and libraries.
* Packages to integrate Swoole with popular PHP frameworks, including Laravel, Symfony, Slim, and Yii.
* Books, videos, and other learning materials about Swoole.
* Debugging, profiling, and testing tools for developing Swoole-based applications.
* Coroutine-friendly packages and libraries.
* Other Swoole related projects and resources.
## ⨠Event-based
The network layer in Swoole is event-based and takes full advantage of the underlying epoll/kqueue implementation, making it really easy to serve millions of requests.
Swoole 4.x uses a brand new engine kernel and now it has a full-time developer team, so we are entering an unprecedented period in PHP history which offers a unique possibility for rapid evolution in performance.
## â¡ Coroutine
Swoole 4.x or later supports the built-in coroutine with high availability, and you can use fully synchronized code to implement asynchronous performance. PHP code without any additional keywords, the underlying automatic coroutine-scheduling.
Developers can understand coroutines as ultra-lightweight threads, and you can easily create thousands of coroutines in a single process.
### MySQL
Concurrency 10K requests to read data from MySQL takes only 0.2s!
```php
$s = microtime(true);
Co\run(function() {
for ($c = 100; $c--;) {
go(function () {
$mysql = new Swoole\Coroutine\MySQL;
$mysql->connect([
'host' => '127.0.0.1',
'user' => 'root',
'password' => 'root',
'database' => 'test'
]);
$statement = $mysql->prepare('SELECT * FROM `user`');
for ($n = 100; $n--;) {
$result = $statement->execute();
assert(count($result) > 0);
}
});
}
});
echo 'use ' . (microtime(true) - $s) . ' s';
```
### Mixed server
You can create multiple services on the single event loop: TCP, HTTP, Websocket and HTTP2, and easily handle thousands of requests.
```php
function tcp_pack(string $data): string
{
return pack('N', strlen($data)) . $data;
}
function tcp_unpack(string $data): string
{
return substr($data, 4, unpack('N', substr($data, 0, 4))[1]);
}
$tcp_options = [
'open_length_check' => true,
'package_length_type' => 'N',
'package_length_offset' => 0,
'package_body_offset' => 4
];
```
```php
$server = new Swoole\WebSocket\Server('127.0.0.1', 9501, SWOOLE_BASE);
$server->set(['open_http2_protocol' => true]);
// http && http2
$server->on('request', function (Swoole\Http\Request $request, Swoole\Http\Response $response) {
$response->end('Hello ' . $request->rawcontent());
});
// websocket
$server->on('message', function (Swoole\WebSocket\Server $server, Swoole\WebSocket\Frame $frame) {
$server->push($frame->fd, 'Hello ' . $frame->data);
});
// tcp
$tcp_server = $server->listen('127.0.0.1', 9502, SWOOLE_TCP);
$tcp_server->set($tcp_options);
$tcp_server->on('receive', function (Swoole\Server $server, int $fd, int $reactor_id, string $data) {
$server->send($fd, tcp_pack('Hello ' . tcp_unpack($data)));
});
$server->start();
```
### Coroutine clients
Whether you DNS query or send requests or receive responses, all of
没有合适的资源?快使用搜索试试~ 我知道了~
资源推荐
资源详情
资源评论
收起资源包目录
Swoole框架 v5.1.2.zip (2000个子文件)
nghttp2_hd_huffman_data.c 103KB
nghttp2_hd.c 61KB
swoole_http_parser.c 45KB
plain_wrapper.c 41KB
sds.c 39KB
oci_statement.c 38KB
oci_statement.c 36KB
hiredis.c 35KB
pgsql_driver.c 35KB
pgsql_driver.c 33KB
oci_driver.c 27KB
oci_driver.c 27KB
odbc_stmt.c 23KB
read.c 23KB
odbc_stmt.c 22KB
sqlite_driver.c 21KB
pgsql_statement.c 20KB
sqlite_driver.c 20KB
net.c 20KB
pgsql_statement.c 19KB
multipart_parser.c 16KB
odbc_driver.c 14KB
odbc_driver.c 13KB
nghttp2_buf.c 11KB
sqlite_statement.c 10KB
sqlite_statement.c 9KB
nghttp2_helper.c 5KB
class.c 4KB
nghttp2_hd_huffman.c 4KB
client.c 3KB
alloc.c 3KB
nghttp2_rcbuf.c 3KB
nghttp2_mem.c 2KB
swoole_redis_coro.cc 202KB
swoole_server.cc 151KB
swoole_mysql_coro.cc 84KB
swoole_socket_coro.cc 82KB
swoole_http_client_coro.cc 77KB
swoole_runtime.cc 72KB
swoole_postgresql_coro.cc 70KB
master.cc 63KB
swoole_http2_client_coro.cc 58KB
socket.cc 56KB
php_swoole.cc 55KB
swoole_client.cc 55KB
swoole_http_response.cc 49KB
swoole_coroutine.cc 49KB
swoole_http2_server.cc 49KB
socket.cc 43KB
swoole_process.cc 39KB
swoole_http_request.cc 38KB
http.cc 37KB
swoole_websocket_server.cc 36KB
client.cc 36KB
reactor_thread.cc 31KB
swoole_server_port.cc 30KB
process_pool.cc 29KB
swoole_mysql_proto.cc 29KB
swoole_http_server_coro.cc 27KB
port.cc 27KB
ssl.cc 26KB
base.cc 25KB
swoole_event.cc 25KB
dns.cc 24KB
swoole_client_coro.cc 23KB
swoole_process_pool.cc 22KB
swoole_table.cc 21KB
manager.cc 21KB
system.cc 21KB
swoole_admin_server.cc 20KB
swoole_coroutine_system.cc 18KB
swoole_http_server.cc 16KB
worker.cc 16KB
swoole_curl.cc 16KB
mime_type.cc 16KB
hook.cc 15KB
static_handler.cc 14KB
websocket.cc 14KB
async_thread.cc 14KB
swoole_atomic.cc 13KB
swoole_redis_server.cc 13KB
task_worker.cc 13KB
table.cc 13KB
http.cc 12KB
swoole_coroutine_scheduler.cc 12KB
base.cc 12KB
reactor_process.cc 12KB
swoole_timer.cc 11KB
signal.cc 11KB
swoole_odbc.cc 11KB
base.cc 11KB
error.cc 11KB
kqueue.cc 10KB
process.cc 9KB
swoole_name_resolver.cc 9KB
message_bus.cc 9KB
log.cc 9KB
swoole_channel_coro.cc 9KB
redis.cc 8KB
swoole_lock.cc 8KB
共 2000 条
- 1
- 2
- 3
- 4
- 5
- 6
- 20
资源评论
小小姑娘很大
- 粉丝: 4078
- 资源: 2321
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- Python 程序语言设计模式思路-创建型模式:原型模式:通过复制现有对象来创建新对象,面向对象编程
- 卸载软件geek卸载软件geek
- Python 程序语言设计模式思路-创建型模式:单例模式,确保一个类的唯一实例(装饰器)面向对象编程、继承
- skywalking-plugins.jar skywalking-alarm.jar
- 独栋别墅图纸D020-两层-10.00&11.00米- 施工图.dwg
- Python 程序语言设计模式思路-创建型模式:工厂模式,创建对象的统一接口,封装对象的创建逻辑
- python自学教程-05-json数据格式的介绍.ev4.rar
- python自学教程-04-自定义JavaScript.ev4.rar
- 《淘宝后台系统...》
- skywalking-plugins.jar
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功