오늘은 대한입니다.
sun's longitude:299 48 47.09 
· 자유게시판 · 묻고답하기 · 알파문서 · RPMS list
· 사용자문서 · 팁/FAQ모음 · 리눅스Links · 자료실
· 서버정보 · 운영자 · Books/FAQ · FreeBSD
/board/delete.php:소스보기  
알파문서
자주 잊어먹거나, 메모해 둘 필요성이 있는 팁이나 문서, 기타 등등
[*** 쓰기 금지단어 패턴 ***]
글 본문 중간에 업로드할 이미지를 추가하는 방법 : @@이미지이름@@
ex) @@foo.gif@@
 ★ 글 지우기 항목입니다. 한번 더 생각하시고 결정하십시오.!!!
제목 196 : [PHP] imitative Async I/O non-block exec
 이름  산이 [홈]http://linuxchannel.net/
## Async I/O 흉내내기
-------------------------------
<?php
##
## -- san2@2009.02.03
## -- imitative Async I/O non-block execution


## imitative Async I/O run execution
$proc[] = popen('sh ss.sh 8 2>&1','r');
$proc[] = popen('sh ss.sh 10 2>&1','r');
$proc[] = popen('sh ss.sh 20 2>&1','r');

## none-block
foreach($proc AS $fp)
{
stream_set_blocking($fp,0);
$stream[] = $fp;
}
print_r($stream);

while($read = $stream)
{
if(stream_select($read,$w=NULL,$e=NULL,0,500000) === FALSE) continue;
foreach($read AS $fp)
{
//while($buf = fgets($fp,512)) echo $buf;
fpassthru($fp);
if(feof($fp))
{
$key = array_search($fp,$stream);
unset($stream[$key]);
fclose($fp);
}
}
}
exit;
?>
-------------------------------
<?php
## -- san2@2009.02.03
## -- imitative Async I/O non-block execution

## 0=>stdin, 1=>stdout, 2=>stderr
$desp = array(0=>array('pipe','r'), 1=>array('pipe','w'), 2=>array('pipe','w'));

## imitative Async I/O run execution
$proc[] = proc_open('sh ss.sh 8',$desp,$p[]);
$proc[] = proc_open('sh ss.sh 10',$desp,$p[]);
$proc[] = proc_open('sh ss.sh 20',$desp,$p[]);

## set non-block
foreach($p AS $fp)
{
fclose($fp[0]);
stream_set_blocking($fp[1],0);
$stream[] = $fp[1];
}
print_r($stream);

while($read = $stream)
{
if(stream_select($read,$w=NULL,$e=NULL,0,500000) === FALSE) continue;
foreach($read AS $fp)
{
//while($buf = fgets($fp,512)) echo $buf;
fpassthru($fp);
if(feof($fp))
{
$key = array_search($fp,$stream);
unset($stream[$key]);
fclose($fp);
fclose($p[$key][2]);
proc_close($proc[$key]);
}
}
}
exit;
?>
-------------------------------
<?php
## -- san2@2009.02.03
## -- imitative Async I/O non-block execution, simple but not good

## 0=>stdin, 1=>stdout, 2=>stderr
$desp = array(0=>array('pipe','r'), 1=>array('pipe','w'), 2=>array('pipe','w'));

## imitative Async I/O run execution
$proc = proc_open('/bin/sh -i',$desp,$fp); // zombie

## set non-block
stream_set_blocking($fp[0],0);
stream_set_blocking($fp[1],0);

fwrite($fp[0],'/bin/sh ss.sh 12 2>&1 &');
fwrite($fp[0],'/bin/sh ss.sh 8 2>&1 &');
fwrite($fp[0],'/bin/sh ss.sh 20 2>&1 &');
fclose($fp[0]);

$stream = array($fp[1]);
while(1)
{
if(stream_select($stream,$w=NULL,$e=NULL,0,500000) === FALSE) continue;
while($buf = fgets($fp[1],512)) echo $buf;
//fpassthru($fp[1]);
if(feof($fp[1]))
{
fclose($fp[1]);
fclose($fp[2]);
proc_close($proc);
break;
}
}
exit;
?>
-----------------------------------------
2009년 02월 03일 13:58:37 화(오후)  from 114.111.62.248
0
암호: 공용 보안 SSL 서버가 준비되기 전까지는 off 합니다

apache lighttpd linuxchannel.net 
Copyright 1997-2026. linuxchannel.net. All rights reserved.

Page loading: 0.01(server) + (network) + (browser) seconds