php異步處理

a.phpphp

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

$start = microtime(true);dom

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');url

$end = microtime(true);orm

$time= $end - $start;htm

//精確到十位小數,可自行調節
echo number_format($time, 10, '.', '')." seconds";utf-8


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

file_put_contents('54321.log', microtime(true), FILE_APPEND);it

sleep(20);io

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

相關文章
相關標籤/搜索