php双线程操作

<?php
function runThread()
{
$fp = fsockopen('localhost', 80, $errno, $errmsg);

fputs($fp, "GET /test/doublethread.php?act=b\r\n\r\n"); //这里的第二个参数是HTTP协议中规定的请求头
//不明白的请看RFC中的定义

fclose($fp);
}

function a()
{
$fp = fopen('result_a.log', 'w');
fputs($fp, 'Set in ' . Date('h:i:s', time()) . (double)microtime() . "\r\n");

fclose($fp);
}

function b()
{
print_R(123);exit;
$fp = fopen('result_b.log', 'w');
fputs($fp, 'Set in ' . Date('h:i:s', time()) . (double)microtime() . "\r\n");

fclose($fp);
}

if(!isset($_GET['act'])) $_GET['act'] = 'a';

if($_GET['act'] == 'a')
{
runThread();
a();
}
else if($_GET['act'] == 'b') b();
?>

posted @ 2013-05-09 15:52  hechunhua  阅读(163)  评论(0编辑  收藏  举报