函数别名汇总
优质
小牛编辑
138浏览
2023-12-01
协程短名称
简化协程相关API
的名称书写。可修改php.ini
设置swoole.use_shortname=On/Off
来开启/关闭短名,默认为开启。
所有的 Swoole\Coroutine
前缀的类名映射为Co
。此外还有下面的一些映射:
创建协程
//Swoole\Coroutine::create等价于go函数
go(function () {
co::sleep(0.5);
echo "hello";
});
go("test");
go([$object, "method"]);
通道操作
//Channel可以简写为chan
$c = new chan(1);
$c->push($data);
$c->pop();
延迟执行
//Swoole\Coroutine::defer可以直接用defer
defer(function () use ($db) {
$db->close();
});
协程System API
在4.4.4
版本中系统操作相关的协程API
从Swoole\Coroutine
类中,迁移到了Swoole\Coroutine\System
类中。独立为一个新模块。为了向下兼容,底层依然保留了在Coroutine
类之上的别名方法。
- 例如
Swoole\Coroutine::sleep
对应Swoole\Coroutine\System::sleep
- 例如
Swoole\Coroutine::fgets
对应Swoole\Coroutine\System::fgets
类短别名映射关系
下划线类名风格 (将废弃) | 命名空间风格 |
---|---|
swoole_server | Swoole\Server |
swoole_client | Swoole\Client |
swoole_process | Swoole\Process |
swoole_timer | Swoole\Timer |
swoole_table | Swoole\Table |
swoole_lock | Swoole\Lock |
swoole_atomic | Swoole\Atomic |
swoole_buffer | Swoole\Buffer |
swoole_redis | Swoole\Redis |
swoole_event | Swoole\Event |
swoole_mysql | Swoole\MySQL |
swoole_mmap | Swoole\Mmap |
swoole_channel | Swoole\Channel |
swoole_serialize | Swoole\Serialize |
swoole_http_server | Swoole\Http\Server |
swoole_http_client | Swoole\Http\Client |
swoole_http_request | Swoole\Http\Request |
swoole_http_response | Swoole\Http\Response |
swoole_websocket_server | Swoole\WebSocket\Server |