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条)

报告相同问题?

悬赏问题

  • ¥15 BP神经网络控制倒立摆
  • ¥20 要这个数学建模编程的代码 并且能完整允许出来结果 完整的过程和数据的结果
  • ¥15 html5+css和javascript有人可以帮吗?图片要怎么插入代码里面啊
  • ¥30 Unity接入微信SDK 无法开启摄像头
  • ¥20 有偿 写代码 要用特定的软件anaconda 里的jvpyter 用python3写
  • ¥20 cad图纸,chx-3六轴码垛机器人
  • ¥15 移动摄像头专网需要解vlan
  • ¥20 access多表提取相同字段数据并合并
  • ¥20 基于MSP430f5529的MPU6050驱动,求出欧拉角
  • ¥20 Java-Oj-桌布的计算