Skip to content

Commit c7fb01a

Browse files
author
何平
committed
Update ALPN protocol settings and refactor server setup
Added 'http/1.1' to the 'alpn_protocols' in the SSL configuration for increased compatibility. Updated the server setup in 'tui.php' to use the Swow library for socket operations, removing previous display elements. Adjusted the class map path in 'annotations.php'.
1 parent 73f4221 commit c7fb01a

File tree

3 files changed

+74
-47
lines changed

3 files changed

+74
-47
lines changed

config/autoload/annotations.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@
2121
ArrayShape::class,
2222
],
2323
'class_map' => [
24-
// Server::class => BASE_PATH . '/cloud-admin//Http2/Server/Server.php',
25-
Server::class => BASE_PATH . '/cloud-admin/Server/Server.php',
24+
Server::class => BASE_PATH . '/cloud-admin//Http2/Server/Server.php',
25+
// Server::class => BASE_PATH . '/cloud-admin/Server/Server.php',
2626
],
2727
],
2828
];

config/autoload/ssl.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,6 @@
2323
'certificate_key' => env('CERTIFICATE_KEY'),
2424
'verify_peer' => false,
2525
'verify_peer_name' => false,
26-
'alpn_protocols' => 'h2',
26+
'alpn_protocols' => 'h2,http/1.1',
2727
'allow_self_signed' => true,
2828
];

tui.php

+71-44
Original file line numberDiff line numberDiff line change
@@ -15,50 +15,77 @@
1515
use PhpTui\Tui\Text\Title;
1616
use PhpTui\Tui\Widget\Borders;
1717
use PhpTui\Tui\Widget\Direction;
18+
use Swow\Coroutine;
19+
use Swow\Sync\WaitReference;
1820

1921
require 'vendor/autoload.php';
20-
echo PHP_EOL;
21-
$display = DisplayBuilder::default()->build();
22-
$total = 10;
23-
for ($done = 0; $done <= $total; ++$done) {
24-
// 重置光标位置
25-
echo "\r\033[K";
26-
$display->clear();
27-
$display->draw(
28-
GridWidget::default()
29-
->direction(Direction::Horizontal)
30-
->constraints(
31-
Constraint::percentage(50),
32-
Constraint::percentage(50),
33-
)
34-
->widgets(
35-
BlockWidget::default()->borders(Borders::ALL)->titles(Title::fromString('Left')),
36-
GridWidget::default()
37-
->direction(Direction::Vertical)
38-
->constraints(
39-
Constraint::percentage(50),
40-
Constraint::percentage(50),
41-
)
42-
->widgets(
43-
BlockWidget::default()->borders(Borders::ALL)->titles(Title::fromString('Top Right'))->widget(
44-
\PhpTui\Tui\Extension\Core\Widget\ParagraphWidget::fromText(
45-
\PhpTui\Tui\Text\Text::parse(
46-
<<<EOT
47-
The <fg=green>{$done}</> is the totality of <options=bold>entities</>,
48-
the whole of reality, or everything that is.[1] The nature of the
49-
world has been <fg=red>conceptualized</> differently in different fields. Some
50-
conceptions see the world as unique while others talk of a
51-
plurality of <bg=green>worlds</>.
52-
EOT
53-
)
54-
)
55-
),
56-
BlockWidget::default()->borders(Borders::ALL)->titles(Title::fromString('Bottom Right')),
57-
)
58-
)
59-
);
6022

61-
// 等待一段时间以模拟进程
62-
\usleep(100000);
63-
}
64-
echo PHP_EOL;
23+
24+
$socket = new \Swow\Socket(Swow\Socket::TYPE_TCP);
25+
$server = stream_socket_server('tls://127.0.0.1:9501', context: stream_context_create([
26+
'ssl' => [
27+
'alpn_protocols' => 'h2,http/1.1',
28+
'local_cert' => __DIR__ . '/ssl/server.crt',
29+
'local_pk' => __DIR__ . '/ssl/server.key',
30+
'verify_peer' => false,
31+
'verify_peer_name' => false,
32+
'allow_self_signed' => true,
33+
],
34+
]));
35+
$wr = new WaitReference();
36+
Coroutine::run(static function () use ($server, $wr): void {
37+
$conn = stream_socket_accept($server);
38+
$payload = fread($conn, 1024);
39+
if (str_contains($payload, 'PRI * HTTP/2.0')) {
40+
echo "ALPN uses HTTP/2.0\n";
41+
} else {
42+
echo "ALPN uses HTTP/1.1\n";
43+
}
44+
});
45+
46+
$wr::wait($wr);
47+
//echo PHP_EOL;
48+
//$display = DisplayBuilder::default()->build();
49+
//$total = 10;
50+
//for ($done = 0; $done <= $total; ++$done) {
51+
// // 重置光标位置
52+
// echo "\r\033[K";
53+
// $display->clear();
54+
// $display->draw(
55+
// GridWidget::default()
56+
// ->direction(Direction::Horizontal)
57+
// ->constraints(
58+
// Constraint::percentage(50),
59+
// Constraint::percentage(50),
60+
// )
61+
// ->widgets(
62+
// BlockWidget::default()->borders(Borders::ALL)->titles(Title::fromString('Left')),
63+
// GridWidget::default()
64+
// ->direction(Direction::Vertical)
65+
// ->constraints(
66+
// Constraint::percentage(50),
67+
// Constraint::percentage(50),
68+
// )
69+
// ->widgets(
70+
// BlockWidget::default()->borders(Borders::ALL)->titles(Title::fromString('Top Right'))->widget(
71+
// \PhpTui\Tui\Extension\Core\Widget\ParagraphWidget::fromText(
72+
// \PhpTui\Tui\Text\Text::parse(
73+
// <<<EOT
74+
// The <fg=green>{$done}</> is the totality of <options=bold>entities</>,
75+
// the whole of reality, or everything that is.[1] The nature of the
76+
// world has been <fg=red>conceptualized</> differently in different fields. Some
77+
// conceptions see the world as unique while others talk of a
78+
// plurality of <bg=green>worlds</>.
79+
// EOT
80+
// )
81+
// )
82+
// ),
83+
// BlockWidget::default()->borders(Borders::ALL)->titles(Title::fromString('Bottom Right')),
84+
// )
85+
// )
86+
// );
87+
//
88+
// // 等待一段时间以模拟进程
89+
// \usleep(100000);
90+
//}
91+
//echo PHP_EOL;

0 commit comments

Comments
 (0)