
说明
1、管道是比较常用的多进程通信手段,管道分为无名管道与有名管道。
2、无名管道只能用于具有亲缘关系的进程间通信,而有名管道可以用于同一主机上任意进程。
实例
$pipe_path='/data/test.pipe';
if(!file_exists($pipe_path)){
if(!posix_mkfifo($pipe_path,0664)){
exit("createpipeerror!");
}
}
$pid=pcntl_fork();
if($pid==0){
//子进程,向管道写数据
$file=fopen($pipe_path,'w');
while(true){
fwrite($file,'helloworld');
$rand=rand(1,3);
sleep($rand);
}
exit('childend!');
}else{
//父进程,从管道读数据
$file=fopen($pipe_path,'r');
while(true){
$rel=fread($file,20);
echo"{$rel}\n";
$rand=rand(1,2);
sleep($rand);
}
}
以上就是php多进程通信之管道的介绍,希望对大家有所帮助。更多php学习指路:php教程
© 版权声明
文章版权归作者所有,未经允许请勿转载。
THE END



















































暂无评论内容