命令行中的Web服务器

I'm trying to have a login page where it logs all login attempts to another command line file which is Login_Server.php.

My current method is a bit of an "outcast" because, basically when you login it'll insert in a database Whoever logged in from 127.0.0.1, and my Login_Server.php looks like this:

<?php
  echo "Server Listening 
";
  while(1) {
    while($row) {
      echo $row['login_msg'] . "
";
      DELETE login_msg from sql
    }
    sleep(1);
  }
?>

So it's not a good way to do it. Is there another way as simple as this that uses sockets, or something more 'efficient'?