您当前的位置: 首页 > 慢生活 > 程序人生 网站首页程序人生
workerman的http服务-基本调试
发布时间:2021-12-11 23:55:23编辑:雪饮阅读()
基本调试
WorkerMan有两种运行模式,调试模式以及daemon运行模式
运行 php start.php start 进入调试模式,这时代码中的echo、var_dump、var_export等函数打印会在终端显示。注意以php start.php start运行的WorkerMan在终端关闭时所有进程会退出。
而运行 php start.php start -d则是进入daemon模式,也就是正式上线的运行模式,关闭终端不受影响。
如果想daemon方式运行时也能看到echo、var_dump、var_export等函数打印,可以设置Worker::$stdoutFile属性,例如
实例:
<?php
use Workerman\Worker;
use Workerman\Connection\TcpConnection;
require_once __DIR__ . '/vendor/autoload.php';
// 将屏幕打印输出到Worker::$stdoutFile指定的文件中
Worker::$stdoutFile = '/tmp/stdout.log';
$http_worker = new Worker("http://0.0.0.0:2345");
$http_worker->onMessage = function(TcpConnection $connection, $data)
{
var_dump("你好!");
$connection->send('hello world');
};
Worker::runAll();
?>
这样所有的echo、var_dump、var_export等函数打印会写入到Worker::$stdoutFile指定的文件中。注意Worker::$stdoutFile指定的路径要有可写权限。
实例运行:
[root@localhost workerman]# /usr/local/php734/bin/php -c /usr/local/php734/lib/php/php.ini start.php start -d
Workerman[start.php] start in DAEMON mode
----------------------------------------- WORKERMAN -----------------------------------------
Workerman version:4.0.22 PHP version:7.3.4
------------------------------------------ WORKERS ------------------------------------------
proto user worker listen processes status
tcp root none http://0.0.0.0:2345 1 [OK]
---------------------------------------------------------------------------------------------
Input "php start.php stop" to stop. Start success.
elinks请求试试:
[root@localhost workerman]# elinks http://127.0.0.1:2345 -dump
hello world
结果日志如预期一样的就出来了:
[root@localhost workerman]# cat /tmp/stdout.log
string(9) "你好!"
关键字词:workerman,http,调试,基本
相关文章
- workerman的http服务-SSE(推送服务,服务端主推)
- workerman的http服务-session管理-更改存储驱动
- workerman的http服务-session管理-设置session存储位
- workerman的http服务-session管理-更改session存储引
- workerman的http服务-session会话-判断对应session数
- workerman的http服务-session会话-删除所有session数
- workerman的http服务-session会话-获取并删除session
- workerman的http服务-session会话-删除session数据
- workerman的http服务-session会话-存储session
- workerman的http服务-session会话-获取session中某个