Trying to use shell_exec, exec, system, passthru, etc.

Need help installing PHP, configuring a script, or configuring a server? Then come on in and post your questions! We'll try to help the best we can!

Moderator: General Moderators

Post Reply
User avatar
Luke
The Ninja Space Mod
Posts: 6424
Joined: Fri Aug 05, 2005 1:53 pm
Location: Paradise, CA

Trying to use shell_exec, exec, system, passthru, etc.

Post by Luke »

I'm attempting to use a library called "ffmpeg" to convert mpeg files to flv on the fly when users upload them. I have downloaded and installed "ffmpeg" on my server and when I use it over ssh, it works exactly as expected. But for some reason, when I try the same exact command using "exec()", "shell_exec()", "system()", the back-tick operator, etc. it doesn't work.

Does anybody know why these functions would not work? PHP is running as the same user I was using for SSH, so it isn't that. Any other suggestions? :(
User avatar
Eran
DevNet Master
Posts: 3549
Joined: Fri Jan 18, 2008 12:36 am
Location: Israel, ME

Re: Trying to use shell_exec, exec, system, passthru, etc.

Post by Eran »

It's probably permissions. Are you sure PHP is running as the same user? it usually runs as apache or nobody
User avatar
VladSun
DevNet Master
Posts: 4313
Joined: Wed Jun 27, 2007 9:44 am
Location: Sofia, Bulgaria

Re: Trying to use shell_exec, exec, system, passthru, etc.

Post by VladSun »

Try

Code: Select all

echo `/full/path/to/ffmpeg ..... 2>&1`;
There are 10 types of people in this world, those who understand binary and those who don't
User avatar
Luke
The Ninja Space Mod
Posts: 6424
Joined: Fri Aug 05, 2005 1:53 pm
Location: Paradise, CA

Re: Trying to use shell_exec, exec, system, passthru, etc.

Post by Luke »

pytrin wrote:It's probably permissions. Are you sure PHP is running as the same user? it usually runs as apache or nobody
Well, I ran "passthru('whoami')" inside PHP and it output "tvmed".
User avatar
Luke
The Ninja Space Mod
Posts: 6424
Joined: Fri Aug 05, 2005 1:53 pm
Location: Paradise, CA

Re: Trying to use shell_exec, exec, system, passthru, etc.

Post by Luke »

VladSun wrote:Try

Code: Select all

echo `/full/path/to/ffmpeg ..... 2>&1`;
Forgive my ignorance, but what parts of that do you mean literally and what parts do you mean to replace args etc. with? Did you mean something like:

Code: Select all

echo `/usr/local/bin/ffmpeg '/path/to/file.mpeg' '/path/to/file.flv'`
Or did you mean to output the 2>&1 part literally?
User avatar
VladSun
DevNet Master
Posts: 4313
Joined: Wed Jun 27, 2007 9:44 am
Location: Sofia, Bulgaria

Re: Trying to use shell_exec, exec, system, passthru, etc.

Post by VladSun »

Code: Select all

echo `/usr/local/bin/ffmpeg '/path/to/file.mpeg' '/path/to/file.flv' 2>&1`;
Shame on you - viewtopic.php?f=1&t=88741 :P :twisted:
There are 10 types of people in this world, those who understand binary and those who don't
Post Reply