오늘은 대한입니다.
sun's longitude:299 44 13.14 
· 자유게시판 · 묻고답하기 · 알파문서 · RPMS list
· 사용자문서 · 팁/FAQ모음 · 리눅스Links · 자료실
· 서버정보 · 운영자 · Books/FAQ · FreeBSD
/board/read.php:소스보기  
알파문서
자주 잊어먹거나, 메모해 둘 필요성이 있는 팁이나 문서, 기타 등등
[*** 쓰기 금지단어 패턴 ***]
글 본문 중간에 업로드할 이미지를 추가하는 방법 : @@이미지이름@@
ex) @@foo.gif@@
196 번 글: [PHP] imitative Async I/O non-block exec
글쓴이: 산이 [홈페이지] 글쓴날: 2009년 02월 03일 13:58:37 화(오후) 조회: 3345
## 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;
?>
-----------------------------------------

 
이전글 : [apache2.2] 모듈 설치
다음글 : [PHP] socket_connect_status  
 from 114.111.62.248
JS(Redhands)Board 0.4 +@

|글쓰기| |답장쓰기| |수정| |삭제|
|이전글| |다음글| |목록보기|
인쇄용 

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

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