测试代码如下:
<?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测试,还是等运算完了,一次性输出。

What’s still popular is the ease of use, flexibility and a strong ecosystem. 1) Ease of use and simple syntax make it the first choice for beginners. 2) Closely integrated with web development, excellent interaction with HTTP requests and database. 3) The huge ecosystem provides a wealth of tools and libraries. 4) Active community and open source nature adapts them to new needs and technology trends.

PHP and Python are both high-level programming languages that are widely used in web development, data processing and automation tasks. 1.PHP is often used to build dynamic websites and content management systems, while Python is often used to build web frameworks and data science. 2.PHP uses echo to output content, Python uses print. 3. Both support object-oriented programming, but the syntax and keywords are different. 4. PHP supports weak type conversion, while Python is more stringent. 5. PHP performance optimization includes using OPcache and asynchronous programming, while Python uses cProfile and asynchronous programming.

PHP is mainly procedural programming, but also supports object-oriented programming (OOP); Python supports a variety of paradigms, including OOP, functional and procedural programming. PHP is suitable for web development, and Python is suitable for a variety of applications such as data analysis and machine learning.

PHP originated in 1994 and was developed by RasmusLerdorf. It was originally used to track website visitors and gradually evolved into a server-side scripting language and was widely used in web development. Python was developed by Guidovan Rossum in the late 1980s and was first released in 1991. It emphasizes code readability and simplicity, and is suitable for scientific computing, data analysis and other fields.

PHP is suitable for web development and rapid prototyping, and Python is suitable for data science and machine learning. 1.PHP is used for dynamic web development, with simple syntax and suitable for rapid development. 2. Python has concise syntax, is suitable for multiple fields, and has a strong library ecosystem.

PHP remains important in the modernization process because it supports a large number of websites and applications and adapts to development needs through frameworks. 1.PHP7 improves performance and introduces new features. 2. Modern frameworks such as Laravel, Symfony and CodeIgniter simplify development and improve code quality. 3. Performance optimization and best practices further improve application efficiency.

PHPhassignificantlyimpactedwebdevelopmentandextendsbeyondit.1)ItpowersmajorplatformslikeWordPressandexcelsindatabaseinteractions.2)PHP'sadaptabilityallowsittoscaleforlargeapplicationsusingframeworkslikeLaravel.3)Beyondweb,PHPisusedincommand-linescrip

PHP type prompts to improve code quality and readability. 1) Scalar type tips: Since PHP7.0, basic data types are allowed to be specified in function parameters, such as int, float, etc. 2) Return type prompt: Ensure the consistency of the function return value type. 3) Union type prompt: Since PHP8.0, multiple types are allowed to be specified in function parameters or return values. 4) Nullable type prompt: Allows to include null values and handle functions that may return null values.


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

DVWA
Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software

VSCode Windows 64-bit Download
A free and powerful IDE editor launched by Microsoft

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

SAP NetWeaver Server Adapter for Eclipse
Integrate Eclipse with SAP NetWeaver application server.

Dreamweaver Mac version
Visual web development tools