//ignore_user_abort(true);//是否忽略浏览器的断开而继续执行脚本 header( 'Content-Type: text/html;charset=utf-8' ); echo str_pad("",1000); //输出1000个空格(浏览器需要接受一定长度的数据之后才会输出内容) echo 'begin...<br>'; ob_flush(); flush(); for($i=0;$i'; if ( connection_aborted() )//检查是否断开客户机。 如果已终止连接,则该函返回 1,否则返回 0 { exit; } ob_flush(); flush(); sleep(1);//睡眠一秒 } echo 'ok';/*
First clarify the output order of PHP
1. Turn on the php output cache: echo,print -> php output_buffring -> server buffering -> browser buffering -> browser display
2. Not open php Output cache: echo, print -> server buffering -> browser buffering -> browser display
Also clarify the browser's output cache: IE is 256Bytes, Chrome and FireFox are 1000Bytes, only the output data reaches this length or script The data will be output on the page only after the browser is terminated
Let’s talk about several PHP settings and APIs used:
output_buffering configuration in 1.php.ini
?Off: means turning off PHP output caching
?On: turning on unlimited Large output cache
?4096: Turn on the output cache with a size of 4096Byte
Implicit_flush configuration in 2.php.ini
?On: Indicates that after each output (such as echo, print), the flush() function is automatically called and the output is directed
?Off: Contrary to On, flush() will not be called after each output. It needs to wait until the server buffering is full before outputting. However, we can use the flush() function to replace it. It doesn’t matter if it is not enabled, but it is more flexible
3 .ob_flush() function: Take out the data from PHP buffering and put it into server buffering
4.flush() function: Take out the data from Server buffering and put it into browser buffering
5.ob_start() function: Open a buffer on the server Save all output. So anytime echo is used, the output will be added to the buffer until the program ends or is terminated using ob_flush(). Then the contents of the buffer in the server will be sent to the browser, which will be parsed and displayed by the browser.
ob_* series of functions operate the output buffer of PHP itself.
ob_get_contents() - Returns the contents of the output buffer
ob_flush( ) - flush out (send out) the contents of the output buffer
ob_clean() - clear (erase) the output buffer
ob_end_flush() - flush out (send out) the contents of the output buffer and close the buffer
ob_end_clean() - clear ( Erase) buffer and close the output buffer
flush() - Flush the output buffer
Summary:
ob_flush is to flush PHP's own buffer.
The function ob_end_clean will clear the contents of the buffer and close the buffer, but will not output content.
At this time, a function ob_get_contents() must be used in front of ob_end_clean() to obtain the contents of the buffer.
In this case, the content can be saved to a variable before executing ob_end_clean(), and then the variable can be operated after ob_end_clean()
Can be used to cache static html content
Note: flush, strictly speaking, This only has practical effect when PHP is installed as a Module (handler or filter) of apache. It refreshes the buffer of WebServer (which can be considered to refer specifically to apache).
1. Under the sapi of apache module, flush will By calling the flush member function pointer of sapi_module, the api of apache is indirectly called: ap_rflush refreshes the output buffer of apache. Of course, the manual also says that there are some other modules of apache that may change the result of this action..
2 .Some Apache modules, such as mod_gzip, may perform output caching themselves, which will cause the results generated by the flush() function to not be sent to the client browser immediately.
Even the browser will cache the received content before displaying it. For example, the Netscape browser caches content until it receives a newline or the beginning of an html tag, and does not display an entire table until it receives a tag.
3. Some versions of Microsoft Internet Explorer will only start to display the page after receiving 256 bytes, so some additional spaces must be sent to allow these browsers to display the page content.
So, the correct order to use the two is: ob_flush first, then flush.
Of course, under other sapi, you can not call flush, but in order to ensure the portability of your code, it is recommended to use it together.
*/
Source:
http:// bbs.csdn.net/topics/310167610
http://my.oschina.net/miaowang/blog/349290
http://www.cnblogs.com/daxian2012/archive/2012/ 09/12/2682136.html
Thank you all for your selfless sharing!
The above introduces the sorting of data output while executing PHP, including aspects of it. I hope it will be helpful to friends who are interested in PHP tutorials.

PHPidentifiesauser'ssessionusingsessioncookiesandsessionIDs.1)Whensession_start()iscalled,PHPgeneratesauniquesessionIDstoredinacookienamedPHPSESSIDontheuser'sbrowser.2)ThisIDallowsPHPtoretrievesessiondatafromtheserver.

The security of PHP sessions can be achieved through the following measures: 1. Use session_regenerate_id() to regenerate the session ID when the user logs in or is an important operation. 2. Encrypt the transmission session ID through the HTTPS protocol. 3. Use session_save_path() to specify the secure directory to store session data and set permissions correctly.

PHPsessionfilesarestoredinthedirectoryspecifiedbysession.save_path,typically/tmponUnix-likesystemsorC:\Windows\TemponWindows.Tocustomizethis:1)Usesession_save_path()tosetacustomdirectory,ensuringit'swritable;2)Verifythecustomdirectoryexistsandiswrita

ToretrievedatafromaPHPsession,startthesessionwithsession_start()andaccessvariablesinthe$_SESSIONarray.Forexample:1)Startthesession:session_start().2)Retrievedata:$username=$_SESSION['username'];echo"Welcome,".$username;.Sessionsareserver-si

The steps to build an efficient shopping cart system using sessions include: 1) Understand the definition and function of the session. The session is a server-side storage mechanism used to maintain user status across requests; 2) Implement basic session management, such as adding products to the shopping cart; 3) Expand to advanced usage, supporting product quantity management and deletion; 4) Optimize performance and security, by persisting session data and using secure session identifiers.

The article explains how to create, implement, and use interfaces in PHP, focusing on their benefits for code organization and maintainability.

The article discusses the differences between crypt() and password_hash() in PHP for password hashing, focusing on their implementation, security, and suitability for modern web applications.

Article discusses preventing Cross-Site Scripting (XSS) in PHP through input validation, output encoding, and using tools like OWASP ESAPI and HTML Purifier.


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

SublimeText3 English version
Recommended: Win version, supports code prompts!

ZendStudio 13.5.1 Mac
Powerful PHP integrated development environment

MantisBT
Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

Dreamweaver CS6
Visual web development tools

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),
