首页 > Web开发 > 详细

php异步处理

时间:2020-01-21 12:03:01      阅读:70      评论:0      收藏:0      [点我收藏+]

a.php

<?php
header("Content-type: text/html; charset=utf-8");
date_default_timezone_set("Asia/Shanghai");

$start = microtime(true);

function fsockopen_get($domain, $url)
{
$fp = fsockopen($domain, 80, $errno, $errstr, 30);
if (!$fp) {
echo "$errstr ($errno)<br />\n";
} else {
$out = "GET " . $url . " / HTTP/1.1\r\n";
$out .= "Host: " . $domain . "\r\n";
$out .= "Connection: Close\r\n\r\n";
fwrite($fp, $out);
/*忽略执行结果
while (!feof($fp)) {
echo fgets($fp, 128);
}*/
fclose($fp);
}
}
fsockopen_get(‘temp.com‘, ‘/b.php‘);

$end = microtime(true);

$time= $end - $start;

//精确到十位小数,可自行调节
echo number_format($time, 10, ‘.‘, ‘‘)." seconds";


b.php
<?php
header("Content-type: text/html; charset=utf-8");

file_put_contents(‘54321.log‘, microtime(true), FILE_APPEND);

sleep(20);

file_put_contents(‘54321.log‘, microtime(true), FILE_APPEND);

php异步处理

原文:https://www.cnblogs.com/WebLinuxStudy/p/12220975.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!