Skip to content

Commit

Permalink
Update ALPN protocol settings and refactor server setup
Browse files Browse the repository at this point in the history
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'.
  • Loading branch information
何平 committed Dec 11, 2023
1 parent 73f4221 commit c7fb01a
Show file tree
Hide file tree
Showing 3 changed files with 74 additions and 47 deletions.
4 changes: 2 additions & 2 deletions config/autoload/annotations.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@
ArrayShape::class,
],
'class_map' => [
// Server::class => BASE_PATH . '/cloud-admin//Http2/Server/Server.php',
Server::class => BASE_PATH . '/cloud-admin/Server/Server.php',
Server::class => BASE_PATH . '/cloud-admin//Http2/Server/Server.php',
// Server::class => BASE_PATH . '/cloud-admin/Server/Server.php',
],
],
];
2 changes: 1 addition & 1 deletion config/autoload/ssl.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,6 @@
'certificate_key' => env('CERTIFICATE_KEY'),
'verify_peer' => false,
'verify_peer_name' => false,
'alpn_protocols' => 'h2',
'alpn_protocols' => 'h2,http/1.1',
'allow_self_signed' => true,
];
115 changes: 71 additions & 44 deletions tui.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,50 +15,77 @@
use PhpTui\Tui\Text\Title;
use PhpTui\Tui\Widget\Borders;
use PhpTui\Tui\Widget\Direction;
use Swow\Coroutine;
use Swow\Sync\WaitReference;

require 'vendor/autoload.php';
echo PHP_EOL;
$display = DisplayBuilder::default()->build();
$total = 10;
for ($done = 0; $done <= $total; ++$done) {
// 重置光标位置
echo "\r\033[K";
$display->clear();
$display->draw(
GridWidget::default()
->direction(Direction::Horizontal)
->constraints(
Constraint::percentage(50),
Constraint::percentage(50),
)
->widgets(
BlockWidget::default()->borders(Borders::ALL)->titles(Title::fromString('Left')),
GridWidget::default()
->direction(Direction::Vertical)
->constraints(
Constraint::percentage(50),
Constraint::percentage(50),
)
->widgets(
BlockWidget::default()->borders(Borders::ALL)->titles(Title::fromString('Top Right'))->widget(
\PhpTui\Tui\Extension\Core\Widget\ParagraphWidget::fromText(
\PhpTui\Tui\Text\Text::parse(
<<<EOT
The <fg=green>{$done}</> is the totality of <options=bold>entities</>,
the whole of reality, or everything that is.[1] The nature of the
world has been <fg=red>conceptualized</> differently in different fields. Some
conceptions see the world as unique while others talk of a
plurality of <bg=green>worlds</>.
EOT
)
)
),
BlockWidget::default()->borders(Borders::ALL)->titles(Title::fromString('Bottom Right')),
)
)
);

// 等待一段时间以模拟进程
\usleep(100000);
}
echo PHP_EOL;

$socket = new \Swow\Socket(Swow\Socket::TYPE_TCP);
$server = stream_socket_server('tls://127.0.0.1:9501', context: stream_context_create([
'ssl' => [
'alpn_protocols' => 'h2,http/1.1',
'local_cert' => __DIR__ . '/ssl/server.crt',
'local_pk' => __DIR__ . '/ssl/server.key',
'verify_peer' => false,
'verify_peer_name' => false,
'allow_self_signed' => true,
],
]));
$wr = new WaitReference();
Coroutine::run(static function () use ($server, $wr): void {
$conn = stream_socket_accept($server);
$payload = fread($conn, 1024);
if (str_contains($payload, 'PRI * HTTP/2.0')) {
echo "ALPN uses HTTP/2.0\n";
} else {
echo "ALPN uses HTTP/1.1\n";
}
});

$wr::wait($wr);
//echo PHP_EOL;
//$display = DisplayBuilder::default()->build();
//$total = 10;
//for ($done = 0; $done <= $total; ++$done) {
// // 重置光标位置
// echo "\r\033[K";
// $display->clear();
// $display->draw(
// GridWidget::default()
// ->direction(Direction::Horizontal)
// ->constraints(
// Constraint::percentage(50),
// Constraint::percentage(50),
// )
// ->widgets(
// BlockWidget::default()->borders(Borders::ALL)->titles(Title::fromString('Left')),
// GridWidget::default()
// ->direction(Direction::Vertical)
// ->constraints(
// Constraint::percentage(50),
// Constraint::percentage(50),
// )
// ->widgets(
// BlockWidget::default()->borders(Borders::ALL)->titles(Title::fromString('Top Right'))->widget(
// \PhpTui\Tui\Extension\Core\Widget\ParagraphWidget::fromText(
// \PhpTui\Tui\Text\Text::parse(
// <<<EOT
// The <fg=green>{$done}</> is the totality of <options=bold>entities</>,
// the whole of reality, or everything that is.[1] The nature of the
// world has been <fg=red>conceptualized</> differently in different fields. Some
// conceptions see the world as unique while others talk of a
// plurality of <bg=green>worlds</>.
// EOT
// )
// )
// ),
// BlockWidget::default()->borders(Borders::ALL)->titles(Title::fromString('Bottom Right')),
// )
// )
// );
//
// // 等待一段时间以模拟进程
// \usleep(100000);
//}
//echo PHP_EOL;

0 comments on commit c7fb01a

Please sign in to comment.