LoginSignup
0
0

Laravel sailで、PHP内部からlocalhostへのアクセスができない

Posted at

Laravel sailで、PHP内部からlocalhostへのアクセスができなかった。

問題

いい設計かは別として、Laravel sailのdocker内で、下記のような事をやろうとしても、レスポンスがtimeoutしてできなかった。

file_get_contents('http://localhost/');

理由

Laravel sailのウェブサーバーは、artisan serveコマンドを使っていて、これが同時に1プロセスしか処理できない。つまり、file_get_contentsを呼び出している側のプロセスで既に1プロセス使ってるので、受け側のHTTPリクエストを処理することができない。

解決

artisan serveのプロセス数を増やせばOK。

.env
PHP_CLI_SERVER_WORKERS=16
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0