Pagpapatakbo ng HTTP/1.1 nang walang TLS

Patakbuhin ang HTTP/1.1 nang walang TLS sa 127.0.0.1:9000 para sa lokal na development o sa likod ng HTTPS reverse proxy sa parehong host.

Pag-install ng package

Gumamit ng PHP CLI 8.3 o isang mas bagong bersyon ng 8.x sa isang sinusuportahang Unix system. I-install ang package sa direktoryo ng iyong aplikasyon. Sinusuri ng Composer ang mga kinakailangang extension na pcntl, posix at sockets.

apt · Debian / Ubuntu
Shell
sudo apt update
sudo apt install php-cli php-common composer curl
apk · Alpine 3.24 (community)
Shell
apk add php85 php85-pcntl php85-posix php85-sockets composer curl
pacman · Arch Linux
Shell
sudo pacman -Syu --needed php composer curl
php --ini

I-enable ang sockets sa php.ini ng CLI. Para sa HTTP/2 at HTTP/3, i-enable rin ang ffi.

dnf · Fedora
Shell
sudo dnf install php-cli php-process composer curl
brew · macOS
Shell
brew install php composer curl

Sa terminal para sa pagsubok, gamitin ang curl mula sa Homebrew.

Shell
export PATH="$(brew --prefix curl)/bin:$PATH"
Shell
php -v
composer require mini4work/webserver
composer check-platform-reqs

Pagsisimula ng server

I-save ang halimbawa bilang m4w.json sa root ng aplikasyon at simulan ang bundled handler.

JSON
{
  "listen": { "port": 9000 },
  "protocols": { "http": "1.1" },
  "tls": { "mode": "off" }
}
Shell
php vendor/mini4work/webserver/examples/server.php m4w.json

Pagpapadala ng request

Sa isang pangalawang terminal, magpadala ng isang kahilingan sa loopback listener.

Shell
curl --http1.1 -i http://127.0.0.1:9000/hello

HTTP 200 ang status ng response at JSON ang body nito.

Pagpapatakbo ng HTTP/1.1 gamit ang TLS