Laravel Valet-服务器连接被拒绝或缓慢

Laravel Valet-服务器连接被拒绝或缓慢

一整天都在使用 Laravel 的 Valet 时遇到问题。要么我无法在浏览器中加载网站,要么网站挂起。有时重启 Mac 可以。有时重启 Valet 可以。我正在使用 Homebrew 的 MariaDB 和 PHP70

brew services list
Name    Status  User   Plist
dnsmasq started root   /Library/LaunchDaemons/homebrew.mxcl.dnsmasq.plist
mariadb started jasper /Users/jasper/Library/LaunchAgents/homebrew.mxcl.mariadb.plist
php70   started root   /Library/LaunchDaemons/homebrew.mxcl.php70.plist
tor     stopped        

目前我尝试返回插件概述但它现在挂起了。

执行 netstat 检查会得到一个很长的列表:

sudo netstat -tnlp tcp | grep '\.80 '
tcp4       0      0  127.0.0.1.80           127.0.0.1.54080        ESTABLISHED
tcp4       0      0  127.0.0.1.80           127.0.0.1.54079        ESTABLISHED
tcp4       0      0  127.0.0.1.54080        127.0.0.1.80           ESTABLISHED
tcp4       0      0  127.0.0.1.80           127.0.0.1.54078        ESTABLISHED
tcp4       0      0  127.0.0.1.54079        127.0.0.1.80           ESTABLISHED
tcp4       0      0  127.0.0.1.80           127.0.0.1.54077        ESTABLISHED
tcp4       0      0  127.0.0.1.54078        127.0.0.1.80           ESTABLISHED
tcp4       0      0  127.0.0.1.80           127.0.0.1.54076        ESTABLISHED
tcp4       0      0  127.0.0.1.54077        127.0.0.1.80           ESTABLISHED
tcp4    1318      0  127.0.0.1.80           127.0.0.1.54075        ESTABLISHED
tcp4       0      0  127.0.0.1.54076        127.0.0.1.80           ESTABLISHED
tcp4       0      0  127.0.0.1.54075        127.0.0.1.80           ESTABLISHED
tcp4       0      0  178.20.172.186.54074   205.196.223.93.80      ESTABLISHED
tcp4       0      0  178.20.172.186.54073   205.196.223.93.80      ESTABLISHED
tcp4       0      0  178.20.172.186.54072   192.0.73.2.80          ESTABLISHED
tcp4       0      0  178.20.172.186.54071   192.0.73.2.80          ESTABLISHED
tcp4       0      0  178.20.172.186.54062   151.101.193.69.80      ESTABLISHED
tcp4       0      0  178.20.172.186.54059   151.101.193.69.80
tcp4       0      0  127.0.0.1.54046        127.0.0.1.80           FIN_WAIT_2 
tcp4       0      0  127.0.0.1.80           127.0.0.1.54045        CLOSE_WAIT 
tcp4       0      0  127.0.0.1.80           127.0.0.1.54044        CLOSE_WAIT 
tcp4       0      0  127.0.0.1.54045        127.0.0.1.80           FIN_WAIT_2 
tcp4       0      0  127.0.0.1.54044        127.0.0.1.80           FIN_WAIT_2 
tcp4    1362      0  127.0.0.1.80           127.0.0.1.54043        CLOSE_WAIT 
tcp4    1100      0  127.0.0.1.80           127.0.0.1.54042        CLOSE_WAIT 
tcp4       0      0  127.0.0.1.54043        127.0.0.1.80               CLOSE_WAIT 
tcp4       0      0  127.0.0.1.53966        127.0.0.1.80           FIN_WAIT_2 
tcp4       0      0  127.0.0.1.80           127.0.0.1.53725        CLOSE_WAIT 
tcp4       0      0  127.0.0.1.53725        127.0.0.1.80           FIN_WAIT_2 
tcp4       0      0  127.0.0.1.80           127.0.0.1.53713        CLOSE_WAIT 
tcp4       0      0  127.0.0.1.53713        127.0.0.1.80           FIN_WAIT_2 
tcp4       0      0  127.0.0.1.80           127.0.0.1.53712        CLOSE_WAIT 
tcp4       0      0  127.0.0.1.53712        127.0.0.1.80           FIN_WAIT_2 
tcp4       0      0  127.0.0.1.80           127.0.0.1.53711        CLOSE_WAIT 
tcp4       0      0  127.0.0.1.80           127.0.0.1.53710        CLOSE_WAIT 
tcp4       0      0  127.0.0.1.53711        127.0.0.1.80           FIN_WAIT_2 
tcp4       0      0  127.0.0.1.80           127.0.0.1.53709        CLOSE_WAIT 
tcp4       0      0  127.0.0.1.53710        127.0.0.1.80           FIN_WAIT_2 
tcp4       0      0  127.0.0.1.53709        127.0.0.1.80           FIN_WAIT_2 

这里 lsof 减去 Google 和 DropBox:

lsof -i tcp
COMMAND     PID   USER   FD   TYPE             DEVICE SIZE/OFF NODE NAME
mysqld      559 jasper   25u  IPv4 0xee33df006c9199f1      0t0  TCP localhost:mysql (LISTEN)
TextMate   3408 jasper    7u  IPv6 0xee33df005c2a2ea1      0t0  TCP localhost:52698 (LISTEN)
php-fpm   12857 jasper    0u  IPv4 0xee33df006e0ced19      0t0  TCP localhost:cslistener (LISTEN)
php-fpm   12858 jasper    0u  IPv4 0xee33df006e0ced19      0t0  TCP localhost:cslistener (LISTEN)
php-fpm   12879 jasper    0u  IPv4 0xee33df006e0ced19      0t0  TCP localhost:cslistener (LISTEN)

停止并启动 Valet 让我再次回到本地 WordPress 安装。但这仍然不能解释与 site.dev 的连接被拒绝的问题,也不能解释这一切的缓慢。Valet 应该与 WordPress 一起运行。我检查了 PHP 是否正在运行:

ps aux | grep php
jasper          11529   0.0  0.0  2442020   2060 s000  S+    2:54PM   0:00.00 grep php
jasper          11501   0.0  0.0  2517648   3716   ??  S     2:51PM   0:00.07 /usr/local/opt/php70/sbin/php-fpm --fpm-config /usr/local/etc/php/7.0/php-fpm.conf
jasper          11499   0.0  0.3  2588136  46876   ??  S     2:51PM   0:01.29 /usr/local/opt/php70/sbin/php-fpm --fpm-config /usr/local/etc/php/7.0/php-fpm.conf
jasper          11492   0.0  0.1  2564648  18824   ??  S     2:51PM   0:00.93 /usr/local/opt/php70/sbin/php-fpm --fpm-config /usr/local/etc/php/7.0/php-fpm.conf
root            11487   0.0  0.1  2481744  11428   ??  Ss    2:51PM   0:00.04 /usr/local/opt/php70/sbin/php-fpm --fpm-config /usr/local/etc/php/7.0/php-fpm.conf

看起来还不错。Apache 也没有运行。Valet 日志显示没有信息:

valet logs
No log files were found.

尝试进入插件页面后,我得到了

This site can’t be reached

site.dev refused to connect.
Search Google for domain pure dev admin plugins
ERR_CONNECTION_REFUSED

不过我可以 ping 该网站

ping site.dev
PING site.dev (127.0.0.1): 56 data bytes
64 bytes from 127.0.0.1: icmp_seq=0 ttl=64 time=0.049 ms
64 bytes from 127.0.0.1: icmp_seq=1 ttl=64 time=0.118 ms
64 bytes from 127.0.0.1: icmp_seq=2 ttl=64 time=0.141 ms
^C
--- site.dev ping statistics ---
3 packets transmitted, 3 packets received, 0.0% packet loss
round-trip min/avg/max/stddev = 0.049/0.103/0.141/0.039 ms

我该如何进一步调试该问题?

答案1

好吧,我卸载并重新安装了 Valet,并从 1.1.19 更新到 1.1.22。在此之前,我将 PHP 内存限制增加到 ,memory_limit = 512M/usr/local/etc/php/7.0/php.ini还将最大执行时间增加到 300:。max_execution_time = 300不过,我认为升级确实有所帮助。

之后,我发现越来越多的人在 OSX Sierra 上使用 Laravel Valet 时遇到了问题。找到了这篇关于如何解决 Valet 问题的精彩博客文章这里在 Laravel 新闻。

Caddy 错误日志在这里:~/.valet/Log/error.log

/usr/local/opt/php70/var/log/php-fpm可以检查 PHP 错误。

在 Caddy 日志中我发现:

27/Sep/2016:16:11:55 +0300 [ERROR 502 /server.php] write tcp 127.0.0.1:80->127.0.0.1:49517: write: broken pipe

文章提到错误 502 可能表示 PHP FPM 问题。当我检查 PHP FPM 错误时,我看到:

[27-Sep-2016 16:48:00] NOTICE: [pool www] 'user' directive is ignored when FPM is not running as root
[27-Sep-2016 16:48:00] NOTICE: [pool www] 'group' directive is ignored when FPM is not running as root
[27-Sep-2016 16:48:00] ERROR: unable to bind listening socket for address '127.0.0.1:9000': Address already in use (48)
[27-Sep-2016 16:48:00] ERROR: FPM initialization failed

我敢打赌那才是主要问题。但现在我已经安装了一个全新的 Valet 和一个运行良好的 PHP FPM,应该没问题了。如果不行,我现在知道如何调试了!

相关内容