关于“php请求时长”的问题,小编就整理了【2】个相关介绍“php请求时长”的解答:
php怎么计算脚本运行时间?startTime = microtime(true); //将获取的时间赋值给成员属性$startTime}//脚本结束处嗲用脚本结束的时间微秒值function stop(){$this->stopTime = microtime(true); //将获取的时间赋给成员属性$stopTime}//返回同一脚本中两次获取时间的差值function spent(){//计算后4舍5入保留4位返回return round(($this->stopTime-$this->startTime),4);}} $timer= new Timer();$timer->start(); //在脚本文件开始执行时调用这个方法usleep(1000); //脚本的主题内容,这里可以休眠一毫秒为例$timer->stop(); //在脚本文件结束处调用这个方法 echo "执行该脚本用时".$timer->spent()."
北京"; ?>
如何使用php中的curl方法向服务器发送post请求?用PHP向服务器发送HTTP的POST请求,代码如下:
北京<?php/** * 发送post请求 * @param string $url 请求地址 * @param array $post_data post键值对数据 * @return string */ function send_post($url, $post_data) { $postdata = http_build_query($post_data); $options = array( 'http' => array( 'method' => 'POST', 'header' => 'Content-type:application/x-www-form-urlencoded', 'content' => $postdata, 'timeout' => 15 * 60 // 超时时间(单位:s) ) ); $context = stream_context_create($options); $result = file_get_contents($url, false, $context); return $result; }
北京到此,以上就是小编对于“php请求时长”的问题就介绍到这了,希望介绍关于“php请求时长”的【2】点解答对大家有用。