首页 > php 的for循环是异步执行的吗?

php 的for循环是异步执行的吗?

代码如下:我在php的控制器里设置了两个计时器,想看代码执行的时间,然后出现的问题是,所有输出的时间都是相同的,也就是$starttime,$endtime和$cirtime都是相同的。难道整个循环体在1毫秒内就执行完毕了吗?还是我代码写的有问题?

public function addHotspot(){

    $starttime=time();
    $mHotspot = M("hotspot");
    for ($i=1; $i<=10000; $i++) { 
        $hotspot['scene'] = '1';
        $hotspot['name'] = 'test';
        $hotspot['ath']="0";
        $hotspot['atv']="0";
        $hotspot['type']="3";
        // echo "zzz";
        // $mHotspot->add($hotspot);
        $cirtime=time();
    } 
    $endtime=time();
    $timestrip=$endtime-$starttime;
    $result["result"]=true;
    $result["starttime"]=$starttime;
    $result["endtime"]=$endtime;
    $result["timestrip"]=$timestrip;
    $result["cirtime"]=$cirtime;
    $this->ajaxReturn (json_encode($result),'JSON');
}

不晓得你在说什么
代码也有问题,那个for循环没有意义啊,不停的赋相同的值


php没有异步,而且for在js里面也不是异步的。ps:js里最简单判断是否异步只需要在回调函数里console.log this如果this是window就证明这一步是异步的


不是
PHP 的 time() 单位是秒,1秒内循环一万次不是很正常么……要返回毫秒的话请用 microtime()


肯定不是异步


看你这段代码是循环写数据库,这个习惯可不好

【热门文章】
【热门文章】