Preface
To understand the connection timeout problem between the browser and apache, you need to first understand the keep of http -alive attribute. Let’s briefly introduce keep-alive first. You can find a more detailed introduction online.
The browser and apache are both based on the http protocol. The popular explanation of the keep-alive attribute in the http protocol is that the browser and apache establish a TCP connection for the first time. After the data is transmitted, the TCP connection will not be disconnected immediately, but will continue to wait for the next request. The connection will be disconnected after a period of time (keep-alive-time).
Let’s do a test to check the TCP connection status of apache when it turns on keep-alive support and turns off keep-alive support.
Server | Centos on the virtual machine |
Client | This machine On IE6 browser |
Server address | 192.168.212.128 |
192.168 .212.1 | |
Open the browser to access apache. Use the netstat command to check the connection status.
#netstat –nt|grep –i ’80′
You can see four connections. Because the local access speed is very fast, only the TIME_WAIT status can be captured. Why does the test.html web page have four links?
Looking at the content of test.html, we can know that there are:
1, main.css file
2, main.js file
3, main. jpg picture
4, its own test.html file
so there are four links.
Let’s take a look at the connection status after turning off apache’s keep-alive support.
Restart the server, access test.html with the browser, and check 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 keepAlliveTimeout=15 in httpd.conf, so the connection is closed after 15 seconds after the connection is established.
Conclusions from the testIf you turn off the keep-alive attribute of apache, all files in the accessed page (test.html in the above example), including js, css, pictures, etc. must establish a new TCP connection. There are as many connections as there are referenced files. The specific number of files can be viewed using Firefox's BUG tool.
The bottom 11 requests in the above picture are the number of files that need to be referenced in the web page.
If you enable the keep-alive attribute of apache, all files in the accessed page (test.html in the above example), including js, css, images, etc., will only establish a TCP connection and transfer all files in order. data. Wait for KeepAliveTimeout =15 seconds after all data is transmitted before closing the connection.
References seen on the Internet:If Apache currently responds to 100 user visits per second, KeepAliveTimeOut=5, then the number of httpd processes is 100* 5=500 (prefork mode). If an httpd process consumes 5M of memory, it is 500*5M=2500M=2.5G. Is it an exaggeration? Of course, Apache and Client only made 100 TCP connections. If your memory is large enough, the system load will not be too high. If your memory is less than 2.5G, Swap will be used. Frequent Swap switching will increase the load on the CPU.
Now we turn off KeepAlive, Apache still responds to 100 user visits per second, because we have separated images, js, css, etc., and there is only one request per visit. This At that time, the number of httpd processes was 100*1=100, and the memory used was 100*5M=500M. At this time, Apache and Client also made 100 TCP connections. The performance has improved a lot.
Browser connection timeout
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, name it ReceiveTimeout, and set it to 1000. The default unit of this value is milliseconds, and the time set here is 1 second.
Start when the browser starts accessing the website, and close the connection after 1 second. (The set value is a bit extreme, but it is convenient for display).
Restart the browser to access the website.
Centos on the virtual machine | |||||||||||||
This machine On IE6 browser | |||||||||||||
192.168.212.128 | ##Client address | ||||||||||||
Accessed file index.php | |||||||||||||
服务端 | 虚拟机上的Centos |
客户端 | 本机上IE6浏览器 |
服务端地址 | 192.168.212.128 |
客户端地址 | 192.168.212.1 |
访问的文件index.php | <?php for($i = 0;;$i++){ echo date('H:i:s',time()); echo '<br/>'; flush(); } ?> |
max_execution_time | 30 |
访问index.php。
<?php for($i = 0;;$i++){ echo date('H:i:s',time()); echo '<br/>'; flush(); } ?>
30秒后IE死掉了。为什么呢?答:index.php中有死循环。执行到max_execution_time=30秒后php停止了操作。浏览器这边死掉了。
总结
如果从头到尾看完上面的内容,会得出如下结论:
1,在客户端,浏览器控制着浏览器和apache的最大连接超时时间。
2,在服务端(不打开防火墙),linux和apache都不能控制最大连接超时时间,只有php或者mysql等运行程序通过控制自身的执行时间来控制浏览器和apache的最大连接超时时间。
3,在服务端(打开防火墙),linux上的防火墙和php,mysql等共同控制浏览器和apache的最大连接超时时间。
4,这里的浏览器和apache的最大连接超时时间包括TCP连接中的所有状态超时时间的综合。
更多Apache的相关技术文章,请访问Apache教程栏目进行学习!
The above is the detailed content of How php connects to apache with timeout. For more information, please follow other related articles on the PHP Chinese website!

Apache can serve HTML, CSS, JavaScript and other files. 1) Configure the virtual host and document root directory, 2) receive, process and return requests, 3) use .htaccess files to implement URL rewrite, 4) debug by checking permissions, viewing logs and testing configurations, 5) enable cache, compressing files, and adjusting KeepAlive settings to optimize performance.

ApacheHTTPServer has become a leader in the field of web servers for its modular design, high scalability, security and performance optimization. 1. Modular design supports various protocols and functions by loading different modules. 2. Highly scalable to adapt to the needs of small to large applications. 3. Security protects the website through mod_security and multiple authentication mechanisms. 4. Performance optimization improves loading speed through data compression and caching.

ApacheHTTPServer remains important in modern web environments because of its stability, scalability and rich ecosystem. 1) Stability and reliability make it suitable for high availability environments. 2) A wide ecosystem provides rich modules and extensions. 3) Easy to configure and manage, and can be quickly started even for beginners.

The reasons for Apache's success include: 1) strong open source community support, 2) flexibility and scalability, 3) stability and reliability, and 4) a wide range of application scenarios. Through community technical support and sharing, Apache provides flexible modular design and configuration options, ensuring its adaptability and stability under a variety of needs, and is widely used in different scenarios from personal blogs to large corporate websites.

Apachebecamefamousduetoitsopen-sourcenature,modulardesign,andstrongcommunitysupport.1)Itsopen-sourcemodelandpermissiveApacheLicenseencouragedwidespreadadoption.2)Themodulararchitectureallowedforextensivecustomizationandadaptability.3)Avibrantcommunit

Apache's performance and flexibility make it stand out in a web server. 1) Performance advantages are reflected in efficient processing and scalability, which are implemented through multi-process and multi-threaded models. 2) Flexibility stems from the flexibility of modular design and configuration, allowing modules to be loaded and server behavior adjusted according to requirements.

When the Apache 80 port is occupied, the solution is as follows: find out the process that occupies the port and close it. Check the firewall settings to make sure Apache is not blocked. If the above method does not work, please reconfigure Apache to use a different port. Restart the Apache service.

Apache cannot start because the following reasons may be: Configuration file syntax error. Conflict with other application ports. Permissions issue. Out of memory. Process deadlock. Daemon failure. SELinux permissions issues. Firewall problem. Software conflict.


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

ZendStudio 13.5.1 Mac
Powerful PHP integrated development environment

mPDF
mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

MinGW - Minimalist GNU for Windows
This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Dreamweaver CS6
Visual web development tools