PHP 定时器 边输出边刷新网页
2015-09-23 18:56
766 查看
使用定时器的时候当然想网页能够看到输出,不希望网页直接卡住,定时器结束输出一片。
要做到定时器不卡住输出,只需要两个函数就行了,看下面代码
要做到定时器不卡住输出,只需要两个函数就行了,看下面代码
<?php //定时器测试代码 demo //跟踪定时程序 timerPro.php ignore_user_abort(true); set_time_limit(600); $interval = 10; $stop = 1; do { if ($stop == 10) break; $curTime = date('y-m-d H:i:s', time()); file_put_contents('timer.log', ' Current Time: '.$curTime.' Stop: '.$stop.PHP_EOL, FILE_APPEND); echo $stop."<br>"; $stop++; ob_flush(); flush(); sleep($interval); } while(true); ?>
ob_flush(); flush(); 需要上面两个函数网页就不会卡住了,在windows chrome上测试,缺一不可。
相关文章推荐
- /usr/local/php-fcgi/sbin/php-fpm start启动服务报错
- Elasticsearch-PHP 配置
- thinkphp 钩子的简单实现和总结
- OLAP与OLTP介绍
- URL::to() 与 URL::toRoute()
- php设计模式----工厂模式
- PHP大小写:函数名和类名不区分,变量名区分
- php实现简易聊天室应用代码
- ThinkPHP学习
- PHP error_reporting() 错误控制函数功能详解
- 利用PHP如何实现Socket服务器
- ubantu下配置ftp服务器
- 安装ecshop2.7时候的错误处理 php版本不兼容引起
- php防注入xss攻击
- php 详解spl_autoload_register()函数
- NRPE: Unable to read output 常见问题
- 10个超级有用的PHP代码片段果断收藏
- 两种不同版本的防注入函数
- thinkphp框架使用支付宝
- executing preg_match_all() function with this Regular Expression causes a PHP Segmentation Fault.