Warning: Swoole\Client::connect(): connect to server[127.0.0.1:9500] failed, Error: Connection refused[111] in /root/codeDir/phpCode/hyperf-skeleton/client.php on line 4 bool(false) ~/codeDir/phpCode/hyperf-skeleton #
我们发现,报错:
1
Error: Connection refused[111]
Operation now in progress
这个错误的绝大部分原因是因为连接超时了。
丢包
例如路由器、网关出现了故障,包被丢了。
错误ip
例如客户端请求了一个错误的ip,那么路由器自然也就路由不到。
测试代码如下,客户端代码:
1 2 3 4
<?php
$client = new \Swoole\Client(SWOOLE_SOCK_TCP, SWOOLE_SOCK_SYNC); var_dump($client->connect('8.8.8.8', 9501));
Warning: Swoole\Client::connect(): connect to server[8.8.8.8:9501] failed, Error: Operation in progress[115] in /root/codeDir/phpCode/hyperf-skeleton/client.php on line 4 bool(false) ~/codeDir/phpCode/hyperf-skeleton #
Warning: Swoole\Client::connect(): connect to server[127.0.0.1:9501] failed, Error: Operation in progress[115] in /root/codeDir/phpCode/hyperf-skeleton/client.php on line 7 bool(false)
Warning: Swoole\Client::connect(): connect to server[127.0.0.1:9501] failed, Error: Operation in progress[115] in /root/codeDir/phpCode/hyperf-skeleton/client.php on line 7 bool(false) ^C ~/codeDir/phpCode/hyperf-skeleton #
SYN Flood攻击就是客户端疯狂的给服务端发送SYN包,然后服务端每次都会把请求放到SYN队列里面。但是,客户端不给服务端回ACK包。如果客户端不回ACK包,那么服务端就会给客户端回SYN + ACK包,即第二次握手发送的包。而回复SYN + ACK包的次数就是由tcp_synack_retries参数决定的。如果把tcp_synack_retries设置为0,那么如果服务端没有收到ACK包,那么服务端就不会重试发送SYN + ACK包了,这样就减少了SYN队列里面那个请求的存活时间。因为对于正常的客户端,如果它接收不到服务器回应的SYN + ACK包,它会再次发送SYN包,客户端还是能正常连接的,只是可能在某些情况下建立连接的速度变慢了一点。
tcp_syncookies
tcp_syncookies是这样解释的:
1 2 3
tcp_syncookies (Boolean; since Linux 2.2) Enable TCP syncookies. The kernel must be compiled with CONFIG_SYN_COOKIES. Send out syncookies when the syn backlog queue of a socket overflows. The syncookies feature attempts to protect a socket from a SYN flood attack. This should be used as a last resort, if at all. This is a violation of the TCP protocol, and conflicts with other areas of TCP such as TCP extensions. It can cause problems for clients and relays. It is not recommended as a tuning mechanism for heavily loaded servers to help with overloaded or misconfigured conditions. For recommended alternatives see tcp_max_syn_backlog, tcp_synack_retries, and tcp_abort_on_overflow. 启用 TCP syncookies。 内核必须使用CONFIG_SYN_COOKIES进行编译。套接字的syn backlog queue溢出时发出syncookies。 syncookies特性试图保护套接字免受SYN洪水攻击。如果有必要的话,这应该作为最后的手段。这违反了TCP 协议,并与TCP扩展等其他区域发生冲突。