Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

334
Views
Two commands successfully run manually but fail when run in shell_exec(), giving TimeOut error

I am trying to execute two dmd commands simultaneously using PHP shell_exec(). One command runs Tshark for 5 seconds. The second command runs an .exe file. Tshark is a program which captures network packs transferring over a network interface. The second program (named mtu.exe) sends network packets from my local machine to a remote machine.

Thing is that when I run these commands manually, I run the first command. A moment after that, I run the second one, and all goes well and within a second or so, the expected packets are transferred by mtu.exe and are captured by tshark.exe. Everything works perfectly well.

But then when I run the following script to execute these commands, I get the following output:

$firstCommand = '"C:\Program Files\Wireshark\tshark.exe"  -a duration:5  -w capture.pcapng  2>&1';
echo $firstCommand."<br><br>";

$secondCommand = "mtu.exe -d0 -a43020008 -g43010008 -i987654321 -s"Merry Xmass"  2>&1";
echo $secondCommand."<br><br>";

echo shell_exec($firstCommand . " && " . $secondCommand);

Output:

"C:\Program Files\Wireshark\tshark.exe"  -a duration:5  -w capture.pcapng  2>&1

mtu.exe -d0 -a43020008 -g43010008 -i987654321 -s"Merry Xmass"  2>&1

Fatal error: Maximum execution time of 30 seconds exceeded in C:\xampp\htdocs\Test\index.php on line 10

Line 10 is the line where shell_exec() is. The question how to fix this issue? Why is this happening?

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

Run tshark in the background with & so the shell doesn't wait for it to finish before running mtu. Then use the wait command to wait for the background command to finish.

echo shell_exec($firstCommand . " & " . $secondCommand . "; wait");

This is Unix shell syntax, I don't know if there's anything equivalent in Windows cmd.

over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!