The connection to the mySQL database fails frequently. Why? A year ago, I developed a website that rented a virtual space of PHP + mySQL in linux and has been working normally before. Over the past six months, database connection failures have frequently occurred (1 ~ 1 week ~ 2 times), you need to find the space provider to restart the mysql service: Warning: mysql_connect (): Ca
The connection to the mySQL database fails frequently. Why? A year ago, I developed a website that rented a virtual space of PHP + mySQL in linux and has been working normally before. Over the past six months, database connection failures have frequently occurred (1 ~ 1 week ~ 2 times), you need to find the space provider to restart the mysql service: Warning: mysql_connect (): Ca
The connection to the mySQL database fails frequently. Why? A year ago, I developed a website that rented a virtual space of PHP + mySQL in linux and has been working normally before.
Over the past six months, database connection failures have frequently occurred (1 ~ 1 week ~ 2 times), you need to find a space provider to restart the mysql service:
Warning: mysql_connect (): Can't connect to MySQL server on 'xx. xx. xx. xx' (4) in/www/users/1b2g.com/xxxx.php on line xxxx
I complained to the Space Provider about my own problems, saying that there were no similar problems with other websites on the same host.
Searching on the Internet seems to have caused some netizens to say that mysql_connect () and mysql_close () cannot be used for database operations. As instructed in the article, I changed mysql_connect () to mysql_pconnect (), which seems to have been normal for half a month. However, in the last half month, my website traffic fell due to Baidu's adjustment. In the past two days, the traffic has been restored, and the problem is no longer the first day of the week ~ 2, appears every day:
Warning: mysql_pconnect (): Can't connect to MySQL server on 'xx. xx. xx. xx' (4) in/www/users/1b2g.com/xxxx.php on line xxxx
Especially today, it is useless to restart the service. If it breaks down again and cannot reach the customer service, it is in a hurry.
Please help us find out why? Is it related to the traffic size? How can this problem be solved? Thank you!
A: In this case, some people suggested optimizing the program so that there should be no excessive queries on each page, especially in the loop body. Try not to query the program again, otherwise it will be easily congested. Use the connection pool
But the questioner encountered another problem: I have reduced the number of database connections on each page as much as possible.
At the beginning, there were a large number of page connections (because iframe nesting was used for code reuse). Later, the maximum number of pages optimized was reduced to four; others are generally 1 ~ 2.
Yesterday, I have reduced the number of connections on all pages to less than two. The most visited pages (80% of the total access) only have one connection.
However, the problem occurred again at noon today.
'Xx. xx. xx. xx you should use the domain name or IP address as the host name. In this way, once the DNS or gateway fails, the local port cannot be connected. We recommend that you use localhost as the host name. Localhost automatically uses the pipeline to connect to the local machine when socket is not supported.