zoukankan      html  css  js  c++  java
  • 使用php让浏览器刷新

    使用php让浏览器刷新需要解决几个问题

    1. PHP脚本执行时间限制,默认的是30m 解决办法:set_time_limit();或者修改PHP.ini 设置max_execution_time时间(不推荐)
    2. 如果客户端浏览器关闭,程序可能就被迫终止,解决办法:ignore_user_abort即使关闭页面依然正常执行
    3. 如果程序一直执行很有可能会消耗大量的资源,解决办法使用sleep使用程序休眠一会,然后在执行

    PHP定时执行的代码:

    ?
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    <?php
    ignore_user_abort();//关掉浏览器,PHP脚本也可以继续执行.
    set_time_limit(3000);// 通过set_time_limit(0)可以让程序无限制的执行下去
    $interval=5;// 每隔5s运行
     
    //方法1--死循环
    do{
        echo '测试'.time().'<br/>';
        sleep($interval);// 等待5s   
    }while(true);
     
    //方法2---sleep 定时执行
        require_once './curlClass.php';//引入文件
         
        $curl =new httpCurl();//实例化
        $stime =$curl->getmicrotime();
        for($i=0;$i<=10;$i++){
             
            echo '测试'.time().'<br/>';
            sleep($interval);// 等待5s
             
        }
        ob_flush();
        flush();
        $etime =$curl->getmicrotime();
        echo '<hr>';
        echo round(($etime-stime),4);//程序执行时间
    ?
    1
      

    测试的时候发现这个效率并不是很高,

    QQ截图20111216110444

  • 相关阅读:
    linux下的make命令
    安装pytorch
    CondaError: Downloaded bytes did not match Content-Length
    cv2.VideoCapture(0)
    cv2.imread(),cv2.imshow(),cv2.imwrite()
    unsqueeze()和squeeze()
    django.core.exceptions.ImproperlyConfigured: Error loading MySQLdb module
    Can't connect to MySQL server on '127.0.0.1' (10061)
    ping ip
    _vimrc配置
  • 原文地址:https://www.cnblogs.com/beyondhjjyt/p/3046514.html
Copyright © 2011-2022 走看看