意外伤害是什么意思:php多线程不工作,求助

来源:百度文库 编辑:神马品牌网 时间:2024/05/03 06:36:22
根据网上的资料编了一个伪多进程程序,生产a/b/c三个进程(即另外调用自己页面三次),显示结果表明执行了建立进程的动作,但没有生成任何文件(每个进程应该生成一个文件)。
显示结果:
thread a generated
thread b generated
thread c generated
finished

源程序:
<?php

if (!isset($_GET['act']))
{
thread('a');
thread('b');
thread('c');

echo "finished";

}
else
{
switch($_GET['act'])
{
case 'a':
a();

break;
case 'b':
b();
break;
case 'c';
c();
break;
default:
break;
}
}

function thread($act)
{
global $PHP_SELF;
$host=$_SERVER['HTTP_HOST'];
$h=fsockopen($host,80,$errno,$errstr,30);
if (!$h)
die ($errstr);
fputs($h,"GET $PHP_SELF?act=".$act."\r\n");
fclose($h);
echo "thread $act generated<br>";
}

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()
{
$fp = fopen('result_b.log', 'w');
fputs($fp, 'Set in ' . Date('h:i:s', time()) . (double)microtime() . "\r\n");
fclose($fp);
}

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

?>

fopen('result_a.log', 'w');

改成 fopen('result_a.log', 'a');

http://blog.uoogle.de

这样吗`?