PHP exec() vs system() vs passthru()


What are the differences?

Is there a specific situation or reason for each function? If yes, can you give some examples of those situations? says that they are used to execute external programs. see reference From the examples I see, I don't see any obvious difference.

If I were to simply run a script (bash or python), which function do you recommend me to use?

2/21/2018 7:17:56 AM

They have slightly different purposes.

  • exec() is for calling a system command, and perhaps dealing with the output yourself.
  • system() is for executing a system command and immediately displaying the output - presumably text.
  • passthru() is for executing a system command which you wish the raw return from - presumably something binary.

Regardless, I suggest you not use any of them. They all produce highly unportable code.

3/12/2019 10:40:19 AM

Licensed under: CC-BY-SA with attribution
Not affiliated with: Stack Overflow