이유를 알려 주세요..
글쓴이: kkume / 작성시간: 월, 2010/10/25 - 3:46오후
터미널에서
# tcpdump -p -i eth0 -s 0 -l -w - dst port 3306 | strings -e S
하고 mysql에서 쿼리가 발생할 때마다 바로 화면에 뿌려지는데요..
다음과 같이 php 파일로 해서 실행시키면 buffered 되었다가 뿌려 집니다.
왜 php 스크립트로 실행할 때는
echo $buf 부분에서 바로 화면에 뿌려지지 않는 것인지요?
그리고 php 스크립트에서 화면에 바로 뿌려지게 할 수는 없는 것인지요?
쿼리가 있을 때마다 echo $buf 다음에서 뭔가를 처리 하고자 합니다.
<?php
$handle = popen("tcpdump -p -i eth0 -s 0 -l -w - dst port 3306 | strings -e S 2>&1", 'r');
while ( !feof($handle) )
{
$buf = fgets($handle);
echo $buf;
@ob_flush();
@flush();
}
?>
Forums:


특별히 문제 될건 없을것 같은데요 ㅠㅠ
아래는 php 예제에서 복사 했습니다. ( http://www.php.net/fgets )
$handle = @fopen("/tmp/inputfile.txt", "r"); if ($handle) { while (($buffer = fgets($handle, 4096)) !== false) { echo $buffer; } if (!feof($handle)) { echo "Error: unexpected fgets() fail\n"; } fclose($handle); }아래 예제에 bad 와 good 이 있군요
Some people try to call feof before fgets, and then ignoring the return value of fgets. This method leads to processing value FALSE when reaching the end of file. Bad example: <?php $f = fopen ("fgetstest.php", "r"); $ln= 0; while (! feof ($f)) { $line= fgets ($f); ++$ln; printf ("%2d: ", $ln); if ($line===FALSE) print ("FALSE\n"); else print ($line); } fclose ($f); ?> Good example: <?php $f = fopen ("fgetstest.php", "r"); $ln= 0; while ($line= fgets ($f)) { ++$ln; printf ("%2d: ", $ln); if ($line===FALSE) print ("FALSE\n"); else print ($line); } fclose ($f); ?>좀 상세한 디버깅 메시지를 찍어 보심이 어떻겠습니까?
---------------------------------------------
git init
git add .
git commit -am "project init"
---------------------------------------------
---------------------------------------------
git init
git add .
git commit -am "project init"
---------------------------------------------
댓글 달기