오늘은 대한입니다.
sun's longitude:299 44 12.97 
· 자유게시판 · 묻고답하기 · 알파문서 · RPMS list
· 사용자문서 · 팁/FAQ모음 · 리눅스Links · 자료실
· 서버정보 · 운영자 · Books/FAQ · FreeBSD
/board/read.php:소스보기  
알파문서
자주 잊어먹거나, 메모해 둘 필요성이 있는 팁이나 문서, 기타 등등
[*** 쓰기 금지단어 패턴 ***]
글 본문 중간에 업로드할 이미지를 추가하는 방법 : @@이미지이름@@
ex) @@foo.gif@@
212 번 글: [php] stream_socket_state
글쓴이: 산이 [홈페이지] 글쓴날: 2009년 06월 11일 09:37:59 목(오전) 조회: 2483
스트림 소켓 상태 알아보기


## stream socket resource state, such as fsockopen(), stream_socket_client()
##
## return value
##   -1 : $handle is empty or is not resource or unknown
##    0 : $handle is not ESTABLISHED
##    1 : $handle is ESTABLISHED
## misc
##    @file_exists('/proc/net/tcp') ? define('_PROCTCP','/proc/net/tcp') : '';
##
function stream_socket_state(&$handle, $inode=NULL)
{
  global $__proctcpfp; // self fp of /proc/net/tcp

  if(!defined('_PROCTCP')) return -1;
  if(!$handle || !@is_resource($handle)) return -1;
  if(!is_resource($__proctcpfp) && !$__proctcpfp = fopen(_PROCTCP,'r')) return -1;

  if(!$inode)
  {
    $fstat = @fstat($handle);
    $inode = $fstat['ino'];
    if($inode === FALSE) return -1;
  }

  rewind($__proctcpfp);
  @fgets($__proctcpfp); // firest line to delete
  while(!feof($__proctcpfp)) // fscanf() best speed
  {
    if(fscanf($__proctcpfp,"%d: %s %s %X %s %s %s %d %d %d %x %s %64s\n",
        $null,$null,$null,$st,$null,$null,$null,$null,$null,$ino,$null,$null,$null)
< 13)
        continue;
    if($inode == $ino)
    {
        $st = hexdec($st); // 1 == ESTABLISHED
        break;
    }
  }
  //fclose($__proctcpfp);

  return ($st===1) ? 1 : FALSE;
}


## example

@file_exists('/proc/net/tcp') ? define('_PROCTCP','/proc/net/tcp') : '';
$fp = fsockopen(....);
$state = stream_socket_state($fp);
echo $state;
fclose($fp);

 
이전글 : [php] socket_state
다음글 : [misc] MogileFS  
 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