多个客户端能同时连接到 Laravel 开发服务器吗?

huangapple go评论50阅读模式
英文:

Can multiple clients connect to a Laravel dev server simultaneously?

问题

这可能是 Laravel 开发服务器的限制。我是否有遗漏的设置?

英文:

I have a Laravel app running locally using ./vendor/bin/sail up. I also have a trivial NodeJS server (running locally as well) that waits 60 seconds on each request and returns dummy data. The Laravel app makes a request to the Node app and becomes unresponsive to client requests until the 60 seconds are up.

Is this a limitation of the Laravel dev server? Is there a setting I'm missing?

答案1

得分: 1

Laravel使用sail底层使用php artisan serve,而php artisan serve又使用内置服务器,默认情况下“仅运行一个单线程进程”。

然而,“您可以配置内置的Web服务器以分叉多个工作进程,以便测试需要对内置Web服务器进行多个并发请求的代码。在启动服务器之前,将PHP_CLI_SERVER_WORKERS环境变量设置为所需工作进程的数量。此功能不支持Windows。”

PHP_CLI_SERVER_WORKERS=5添加到我的.env文件中解决了问题。

英文:

Answering my own question.

Laravel uses php artisan serve underneath sail, which in turn uses the built-in server, which by default "runs only one single-threaded process."

However, "You can configure the built-in webserver to fork multiple workers in order to test code that requires multiple concurrent requests to the built-in webserver. Set the PHP_CLI_SERVER_WORKERS environment variable to the number of desired workers before starting the server. This is not supported on Windows."

Adding PHP_CLI_SERVER_WORKERS=5 to my .env file fixed the issue.

huangapple
  • 本文由 发表于 2023年2月8日 13:15:10
  • 转载请务必保留本文链接:https://go.coder-hub.com/75381599.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定