2010-06-14 2 views
3

PHP가 페이지를 성공적으로 연결 한 소켓을 통해 다른 TCP 서버에서 이벤트가 발생하면 웹 서버가 PHP 페이지를 통해 알려주 길 원합니다. 이 이벤트는 TCP 서버가 웹 서버에 메시지를 보내려는 것과 같습니다.이 작업을 수행하는 방법은 무엇입니까?PHP의 이벤트 리스너

답변

2

물론 : 답장을

$fp = fsockopen("tcp://example.com", 8888) OR die("could not connect"); 
while (!feof($fp)) { 
    $pc = fread($handle, 8192); 
    if ($pc === false || strlen($pc) == 0) 
     break; 
    //a new packet has arrived 
    //you should collect the read in a variable and wait 
    //for another packet until you know the message is complete 
    //(depends on the protocol) 
    collect_in_result($pc); 
    if (message_is_complete()) { 
     if (check_event()) { 
      //take action 
     } 
    } 
} 
+0

덕분에,이 코드에서하시기 바랍니다 상황에 대해 설명하시기 바랍니다 수 있을까? – Izza

+0

fsockopen 및 fread (http://www.php.net/fsockopen 및 http://www.php.net/fread)의 설명서 항목을 참조하십시오. 오류를 수정했습니다. 'fopen' 대신'fsockopen '을 사용해야합니다. – Artefacto