The code below will stuck on real_connect() 100%. set_time_limit and default_socket_timeout and MYSQLI_OPT_CONNECT_TIMEOUT have been set, but not working.
I tested on PHP 5.6 and PHP 7.1. mysql driver is mysqlnd.
set_time_limit(30);
ini_set('default_socket_timeout', 10);
$mysql = new mysqli();
$mysql->options(MYSQLI_OPT_CONNECT_TIMEOUT, 5);
$mysql->real_connect('www.baidu.com', 'root', 'xxx', 'xxx', 80);
Questions:
- Why PHP process stuck on
real_connectwhen using host addresswww.baidu.comand port number80? - Why
MYSQLI_OPT_CONNECT_TIMEOUTand the other timeout settings are not working? - For this particular situation, is there any way to set a timeout that can work?