In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/02 Report--
This article will explain in detail how to time out the connection between php and apache. The editor thinks it is very practical, so I share it with you for reference. I hope you can get something after reading this article.
Preface
To understand the connection timeout between the browser and apache, you need to understand the keep-alive property of http. Let's start with a brief introduction to keep-alive, and you can find a more detailed introduction online.
Both the browser and apache are based on the http protocol. The popular interpretation of the keep-alive attribute in the http protocol is that the browser and apache establish a TCP connection for the first time, and the TCP connection will not be disconnected immediately after data transmission, but continue to wait for the next request. Hold for a period of time (keep-alive-time) before the connection is disconnected.
Let's do a test to see the TCP connection status of apache when turning on keep-alive support and turning off keep-alive support.
Centos client on server virtual machine IE6 browser server address 192.168.212.128 client address 192.168.212.1 do you know the file test.html accessed? The color value at An is the same as that at B.
First turn off the keep-alive parameter of apache and open httpd.conf.
Open a browser to access apache. Use the netstat command to view the connection status.
# netstat-nt | grep-I '80'
You can see four connections, because the local access speed is so fast that you can only grab the TIME_WAIT state. Then why does a test.html page have four links?
If you look at the contents of test.html, you can see that there are:
1century main.css file
2J mian.js file
3. Pictures of main.jpg
4, its own test.html file
So there are four connections.
Then take a look at the connection status after turning off keep-alive support for apache.
Restart the server, the browser accesses test.html and is looking at the connection.
# service httpd restart
# netstat-nt | grep-I '80'
You can see that there is only one connection. And the connection status is ESTABLISHED. We set up keepAlliveTimeout=15 in httpd.conf, so the connection was not closed until 15 seconds after the connection was established.
The conclusion of the test
If you turn off the keep-alive property of apache, all files in the visited page (test.html in the example above), including js,css, images, and so on, will establish a new TCP connection. Make as many connections as there are reference files. How many files can be viewed using Firefox's BUG tool.
The bottom 11 requests in the image above are the number of files that need to be referenced on this page.
If the keep-alive attribute of apache is enabled, all files in the visited page (test.html in the example above), including js,css, images, etc., only establish a TCP connection and transfer all data in order. Wait for KeepAliveTimeout = 15 seconds after all data transfer before closing the connection.
References seen on the Internet:
If the current Apache responds to 100 user visits per second, KeepAliveTimeOut=5, the number of httpd processes is 100,500,500 (prefork mode). If a httpd process consumes 5m memory, it is 500*5M=2500M=2.5G, isn't it? Of course, there are only 100 TCP connections between Apache and Client. If your memory is large enough, the system load will not be too high, if your memory is less than 2.5G, you will use Swap, frequent Swap switching will aggravate the Load of CPU.
Now we turn off KeepAlive,Apache and still respond to 100 user visits per second, because we separate images, js, css, and so on, and there is only one request per visit, so the number of processes in httpd is 100, and memory 100*5M=500M is used. At this time, Apache and Client also made 100 TCP connections. But the performance has improved too much.
The browser connection timed out
Each browser has a default connection timeout. The default time for IE6 is 60 minutes.
This value can be modified through the registry.
1. Open the registry: HKEY_CURRENT_USER\ Software\ Microsoft\ Windows\ CurrentVersion\ Internet Settings.
2. Add an item with a DWORD value, named ReceiveTimeout, and set it to 1000. The default unit of this value is milliseconds, which is the 1 second time set here.
Start from the browser to visit the website and close the connection after 1 second. The setting is a bit extreme, but it is easy to display.
Restart the browser to visit the website.
Centos client on server virtual machine IE6 browser server address 192.168.212.128 client address 192.168.212.1 accessed file index.php
You can see that the browser shows that the server cannot be found, but it is accessible to access the test.html just now.
Accessing the index.php shows that the connection was not successful. Because sleep (10) in index.php has a delay of 10 seconds. The connection timeout for IE6 is 1 second. So the connection failed.
You can connect successfully by accessing test.hml. Because it is to access the local server, the transmission speed is very fast, and all the data has been transferred within the 1 second timeout of IE6.
The conclusion of the test
The default connection timeout for IE6 is 60 minutes. This value can be modified through the ReceiveTimeout value in the registry.
Practical use: use IE6 to upload a large file to the server, if the upload time is more than 60 minutes, it will be disconnected.
This is why some websites specifically develop active plug-ins to upload large files of IE6. The user will not actively modify this value.
Apache connection timed out
Looking at the configuration file of apache, you can see that there is a timeout value.
Some people would think that this is the connection timeout parameter of apache.
We set it to timeout = 1 to access index.php.
If you see that it is still accessible, then this timeout is not the connection timeout of apache. Timeout is the maximum value between the previous request received by apache and the arrival of the latter request. You can check the TCP connection status migration in the browser's communication with apache to understand the value of timeout more accurately.
So what is the connection timeout for apache? What is the parameter control?
A: apache does not have a maximum connection timeout, nor does it have a parameter to control the connection timeout. Because apache is at the application layer of the TCP/IP model.
So what does the server control the maximum connection timeout between the browser and the apache?
A: linux
The conclusion of the test
Apache does not have a maximum connection timeout, nor does it have a parameter to control connection timeout. Because apache is at the application layer of the TCP/IP model.
Linux connection timed out
These two parameters can be found in the system configuration of linux about the connection time.
# sysctl-a | grep time
One is to limit the timeout of the FIN_WAIT state.
One is to limit the timeout for keepalive connections.
Conclusion
The default configuration of linux does not control the parameters of browser and apache connection timeout, and the maximum connection time between apache and browser can be controlled only through linux's firewall.
The operation of PHP timed out
Open php.ini and you can see two parameters.
Max_execution_time: the longest time a php program can be executed.
Max_input_time: the longest time a form can be submitted.
These two values are very important. Let's do a test:
Centos client on server virtual machine IE6 browser server address 192.168.212.128 client address 192.168.212.1 accessed file index.phpmax_execution_time30
Visit index.php.
IE died 30 seconds later. Why? A: there is an endless loop in index.php. Php stops the operation after max_execution_time=30 seconds have been executed. The browser side is dead.
Summary
If you read the above from beginning to end, you will come to the following conclusion:
1. On the client side, the browser controls the maximum connection timeout between the browser and apache.
2. On the server side (no firewall is turned on), neither linux nor apache can control the maximum connection timeout. Only running programs such as php or mysql control the maximum connection timeout between the browser and apache by controlling their own execution time.
3. On the server side (turn on the firewall), the firewall on the linux and php,mysql work together to control the maximum connection timeout between the browser and apache.
4, the maximum connection timeout of the browser and apache here includes the synthesis of all state timeouts in the TCP connection.
On the php and apache connection timeout method to share here, I hope the above content can be of some help to you, can learn more knowledge. If you think the article is good, you can share it for more people to see.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.