flush()函数无效?不能实时刷新输出,如何解决呢?
测试代码如下:
<?phpfor($i=0;$i<5;$i++){ echo '<br/>abc___'.$i; ob_flush(); flush(); sleep(1);}ob_end_flush();?>
理论上应该是1秒出来一条是吧?但是我测试的结果是5秒之后才一起出来。
网上查了下有这样说的“个别web服务器程序,特别是Win32下的web服务器程序,在发送结果到浏览器之前,仍然会缓存脚本的输出,直到程序结束为止。 ”我这个是64位的windows的本地xampp的集成环境。
回复讨论(解决方案)
这种无端占用用户带宽的做法是很无聊的
延时输出的效果应在浏览器中用 js 实现
你的代码在 IE 中永远都不会看到期望的效果,因为 IE 需等待缓冲区装满后才解释收到的数据
这种无端占用用户带宽的做法是很无聊的
延时输出的效果应在浏览器中用 js 实现
你的代码在 IE 中永远都不会看到期望的效果,因为 IE 需等待缓冲区装满后才解释收到的数据
额,不是,我知识对这个函数不太了解。我用的chrome在测试。
其实我是想实现这样的效果:比如我写一个脚本批量处理一些文件
但那个过程可能很漫长,给别人用的话,别人都不知道是在执行呢,还是卡死了。
所以想每循环执行成功一次就输出一句xxxx执行成功;
-------------
最类似的就是咱们安装开源软件的时候见到的创建数据表的时候的显示。
但是我自己写的就会在数据表全部创建完之后才能显示。
这种无端占用用户带宽的做法是很无聊的
延时输出的效果应在浏览器中用 js 实现
你的代码在 IE 中永远都不会看到期望的效果,因为 IE 需等待缓冲区装满后才解释收到的数据
我的想法不是“延时”而是“即时”的显示我已完成的操作。不知道版主有什么高招。
同问!我现在也有一个程序要运行几个小时,一直运行,我只能去数据库查看数据来判断是否运行正常。
我的暂时做法只能做个简单的监控。比如在程序中加memcache写入操作,另外写个页面来读取。
同问!我现在也有一个程序要运行几个小时,一直运行,我只能去数据库查看数据来判断是否运行正常。
我的暂时做法只能做个简单的监控。比如在程序中加memcache写入操作,另外写个页面来读取。 有好的办法了,记得分享下 我去看看别的开源的代码在安装的时候是如何实现那个即时显示的效果的。
我又回来了,试试
<?phpecho str_pad('',4096);set_time_limit(50);for($i=0;$i<=5;$i++){ echo $i.'<br />';ob_flush();flush(); sleep(1);}?>
这两天出这个问题的还挺多的。
这个写法在各浏览器测试都没问题,但有童鞋说,这种做法往缓存区写垃圾,可以试试PHP抛出异常,有空研究一下再分享 。
我又回来了,试试
<?phpecho str_pad('',4096);set_time_limit(50);for($i=0;$i<=5;$i++){ echo $i.'<br />';ob_flush();flush(); sleep(1);}?>
这两天出这个问题的还挺多的。
这个写法在各浏览器测试都没问题,但有童鞋说,这种做法往缓存区写垃圾,可以试试PHP抛出异常,有空研究一下再分享 。
试了下,果然OK。机密是在哪里?
我又回来了,试试
<?phpecho str_pad('',4096);set_time_limit(50);for($i=0;$i<=5;$i++){ echo $i.'<br />';ob_flush();flush(); sleep(1);}?>
这两天出这个问题的还挺多的。
这个写法在各浏览器测试都没问题,但有童鞋说,这种做法往缓存区写垃圾,可以试试PHP抛出异常,有空研究一下再分享 。
完全是因为这个?echo str_pad('',4096);
第二个设置时限的可以省略,这个程序跑下来肯定不会超过30秒。
抛出异常,try-catch还可以这样用,学习了,我好好想想!你是一个好人!
嗯嗯,我的这个程序一开始考虑用php_cli,因为程序步骤多,觉得不友好,还是选择页面;但运行时间太长,开着页面反倒成了累赘,还是用cli吧,加油。
嗯嗯,我的这个程序一开始考虑用php_cli,因为程序步骤多,觉得不友好,还是选择页面;但运行时间太长,开着页面反倒成了累赘,还是用cli吧,加油。 今天又试了下用chrome测试,还是等运算完了,一次性输出。

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

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

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

Hot Topics











There are four main error types in PHP: 1.Notice: the slightest, will not interrupt the program, such as accessing undefined variables; 2. Warning: serious than Notice, will not terminate the program, such as containing no files; 3. FatalError: the most serious, will terminate the program, such as calling no function; 4. ParseError: syntax error, will prevent the program from being executed, such as forgetting to add the end tag.

In PHP, password_hash and password_verify functions should be used to implement secure password hashing, and MD5 or SHA1 should not be used. 1) password_hash generates a hash containing salt values to enhance security. 2) Password_verify verify password and ensure security by comparing hash values. 3) MD5 and SHA1 are vulnerable and lack salt values, and are not suitable for modern password security.

PHP and Python each have their own advantages, and choose according to project requirements. 1.PHP is suitable for web development, especially for rapid development and maintenance of websites. 2. Python is suitable for data science, machine learning and artificial intelligence, with concise syntax and suitable for beginners.

PHP is widely used in e-commerce, content management systems and API development. 1) E-commerce: used for shopping cart function and payment processing. 2) Content management system: used for dynamic content generation and user management. 3) API development: used for RESTful API development and API security. Through performance optimization and best practices, the efficiency and maintainability of PHP applications are improved.

HTTP request methods include GET, POST, PUT and DELETE, which are used to obtain, submit, update and delete resources respectively. 1. The GET method is used to obtain resources and is suitable for read operations. 2. The POST method is used to submit data and is often used to create new resources. 3. The PUT method is used to update resources and is suitable for complete updates. 4. The DELETE method is used to delete resources and is suitable for deletion operations.

PHP is a scripting language widely used on the server side, especially suitable for web development. 1.PHP can embed HTML, process HTTP requests and responses, and supports a variety of databases. 2.PHP is used to generate dynamic web content, process form data, access databases, etc., with strong community support and open source resources. 3. PHP is an interpreted language, and the execution process includes lexical analysis, grammatical analysis, compilation and execution. 4.PHP can be combined with MySQL for advanced applications such as user registration systems. 5. When debugging PHP, you can use functions such as error_reporting() and var_dump(). 6. Optimize PHP code to use caching mechanisms, optimize database queries and use built-in functions. 7

PHP handles file uploads through the $\_FILES variable. The methods to ensure security include: 1. Check upload errors, 2. Verify file type and size, 3. Prevent file overwriting, 4. Move files to a permanent storage location.

In PHPOOP, self:: refers to the current class, parent:: refers to the parent class, static:: is used for late static binding. 1.self:: is used for static method and constant calls, but does not support late static binding. 2.parent:: is used for subclasses to call parent class methods, and private methods cannot be accessed. 3.static:: supports late static binding, suitable for inheritance and polymorphism, but may affect the readability of the code.
