ADDENDUM: The problem in the question below is due to the SECOND command. When I comment out the second statement, the first one runs as expected and produces expected results. :s
I needed to run two terminal commands from PHP SIMULTANEOUSLY, and nothing was solving my problem (as you can see here and here, if you want to). The first command is supposed to run Tshark for 5 seconds and capture network traffic (packets). The second command was supposed to generate some network packets and send them. The whole idea is that the network packets produced by the second command should be captured by Tshark, started by the first command.
In other words I needed to start Tshark in the background, and without waiting for it to finish, I needed to run the second command.
Finally I read somewhere if we end a terminal command with an &
, the command is run in the BACKGROUND, and we can continue running other commands in the foreground. I thought this is the SOLUTION to my problem!
Then I wrote the following script.
PROBLEM:
When I execute this script in the browser, the web page keeps LOADING, and the loading never finishes. Also, apparently, tshark keeps running in the background capturing packets, instead of stopping after 5 seconds. I AM SAYING THIS BECAUSE THE PACKETS KEEP ADDING IN THE CAPTURE FILES (capture.pcap
and capture.txt
- the files where packets captured are stored, see the command in the script) UNLESS I MANUALLY END THE LOADING OF THE WEBPAGE IN THE BROWSER.
Also, when I manually stop the loading of the web page and open the capture.pcap
file in wireshark, I see that the packets which were supposed to be sent ONCE by the second command have been sent HUNDREDS of times.
QUESTIONS:
Does this mean that both the commands are being run again and again and again, like in an infinite loop?
There are no loops in the script. Then why is this infinite-loop like behavior? How can I fix this?
SCRIPT:
shell_exec("tshark -a duration:5 -w /var/www/html/Test/capture.pcap -V > capture.txt &");
shell_exec("./mtu -d0 -a43020008 -g43010008 -i987654321 -s'Mary' 2>&1");