dtt78245 2013-05-18 15:06
浏览 23
已采纳

非阻塞php系统调用 - tshark

I am trying to start a tshark process capturing on the interface wlan0 for 5 minutes. As read in other threads I tried to direct output to a file like this:

$log = "sniff-".date("Y-m-d-H-i-s").".txt";
system("sudo tshark -i wlan0 -a duration:300 > /var/www/log".$log);

I was expecting the webserver to start the tshark process and move on. In the error log of the apache I can see the normal output of tshark:

Running as user "root" and group "root". This could be dangerous
Capturing on wlan0
6 packets captured

What do I have to change for tshark to output into this log file and not interrupt the php script? Does a & suffice and if yes, where do I have to put it?

Solution:

system("sudo tshark -i wlan0 -a duration:300 > /var/www/log".$log." &");
  • 写回答

2条回答 默认 最新

  • doubiaokai4998 2013-05-18 15:49
    关注

    By putting the & at the end of the bash cmd it should disconnect it from the running session, but you could try using PHP threads or PHP fork to run the process off as a parallel process, providing your server has the relevant settings and modules installed to enable this.

    system("sudo tshark -i wlan0 -a duration:300 &> /var/www/log".$log.' &');
    

    Also, by adding &> as the redirect mode, it will redirect both STDOUT and STDERR streams to the log file. The messages you were seeing may have come through STDERR and may not otherwise appear in your log file.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?