James John – Software Engineer

Executing Commands through PHP (Linux & Windows)

Its amazing to see PHP interact with the Operating System, as we have Command Prompt in Windows and have the Terminal in Linux PHP can externally execute commands to it and return you the output or null if an error is found.

Basically we have 3 common functions for running commands in PHP, which are:

  1. shell_exec()
  2. exec()
  3. passthru()
  4. Execution Operator ()

What are the differences between the 3 functions?

Well, I have ran 3 of them and came to notice some differences between them but the one I use mostly is the shell_exec();

Or Linux try this

You see the output is returned as string 🙂

The above is the little I know about them, any suggestion is accepted via comment 🙂

James John

Software Engineer