您当前的位置: 首页 > 慢生活 > 程序人生 网站首页程序人生
workerman常见问题-php的几种回调写法-普通函数回调
发布时间:2022-01-13 19:40:39编辑:雪饮阅读()
PHP里通过匿名函数写回调是最方便的,但是除了匿名函数方式的回调,PHP还有其它的回调写法。
源代码
<?php
use Workerman\Worker;
use Workerman\Connection\TcpConnection;
use Workerman\Protocols\Http\Request;
require_once __DIR__ . '/vendor/autoload.php';
$http_worker = new Worker("http://0.0.0.0:2345");
// 匿名函数回调
$http_worker->onMessage = 'on_message';
// 普通函数
function on_message(TcpConnection $connection, Request $request)
{
// 向浏览器发送hello world
$connection->send('hello world common Function');
}
Worker::runAll();
跑起来
[root@localhost workerman]# /www/server/php/73/bin/php -c /www/server/php/73/etc/php.ini index.php start -d
Workerman[index.php] start in DAEMON mode
----------------------------------------- WORKERMAN -----------------------------------------
Workerman version:4.0.26 PHP version:7.3.31
------------------------------------------ WORKERS ------------------------------------------
proto user worker listen processes status
tcp root none http://0.0.0.0:2345 1 [OK]
---------------------------------------------------------------------------------------------
Input "php index.php stop" to stop. Start success.
访问他
[root@localhost workerman]# elinks http://127.0.0.1:2345 --dump
hello world common Function
关键字词:workerman,常见问题,php,回调,普通函数
相关文章
- workerman作爲客戶端系列之socket5即s5代理搭建基於ce
- workerman作爲客戶端系列之http代理搭建
- workerman作爲客戶端-作爲ws或wss客戶端-做為ws客戶端
- workerman創建https服務(普通請求轉https請求,基於寶塔
- workerman創建https服務
- workerman創建wss服務(基於apache基於phpstudy環境)
- workerman創建wss服務-(配置于nginx上作爲nginx的locat
- workerman-常見問題-創建wss服務-直接用Workerman开启
- php7.3對sqlserver2008数据库连接查询
- workerman常见问题-监听ipv6