...

View Full Version : Trouble with exec - silently doesn't run a program



burningdan
08-14-2008, 05:09 AM
Thank you SO MUCH for your time in helping me.

I'm trying to convert videos using ffmpeg, exec'd from a php page.
I've created a shell script that uses all the ffmpeg options I want and takes 2 parameters for input filename and output filename. That shell script works properly when i run it from a shell.

Here's the shell script

#!/bin/sh
whoami
date
echo about to: ffmpeg -i $1 -ar 22050 -ab 32k -r 25 -s 320x240 -vcodec flv -qscale 9.5 $2
#ffmpeg
ffmpeg -i $1 -ar 22050 -ab 32k -r 25 -s 320x240 -vcodec flv -qscale 9.5 $2
echo $?
whoami
(all but the big ffmpeg line is just debugging and curiousity)

when I run it from within my php page by doing:

echo exec( "danffmpeg $cFileName $cFLVName", &$aExecOutput, &$nExecReturn );

echo( "<BR>execoutput:<BR>\r\n" );
print_r( $aExecOutput );
echo( "<BR>execreturn:<BR>\r\n" );
print_r( $nExecReturn );

I get this output:

apache

execoutput: Array ( [0] => 0 [1] => apache [2] => Wed Aug 13 19:32:51 PDT 2008 [3] => about to: ffmpeg -i records/avitest_79.avi -ar 22050 -ab 32k -r 25 -s 320x240 -vcodec flv -qscale 9.5 streams/avitest_79.flv [4] => 1 [5] => apache )

execreturn: 0

The return value of ffmpeg within the script is 1, but the execreturn value of danffmpeg is 0.

When I change the line in the shell script that launches ffmpeg -- I uncomment the unadorned #ffmpeg and comment out the one that includes all the parameters and actually tries to do the conversion...

When I do that, ffmpeg runs. I can see the huge long help screen output in the execoutput. The $? return value of ffmpeg is still 1, and the execreturn value is still 0.

This leads me to believe it's not a permissions problem of launching ffmpeg.
My best guess is that it's not launching because of how much memory (or something) ffmpeg wants to take up when it tries to convert... and I tried setting memory_limit to 256M (from 16M) and it didn't change...

It's an x86_64 system running CentOS 5
I've attached my phpinfo output.

Thank you again for your help
dan

oesxyl
08-14-2008, 07:12 AM
add on top of the php script:


ini_set('display_error',1);
error_reporting(E_ALL);


read the server logs, must be something there, :)

add a -x to shebang to be more chatty, :)


#!/bin/sh -x


use this instead


togo=`ffmpeg -i $1 -ar 22050 -ab 32k -r 25 -s 320x240 -vcodec flv -qscale 9.5 $2`
.....
return $togo

bash return exit code of the last executed command( I assume you don't really use sh, :)).

other problems could related to group/owner of the script, uid, gid.

I hope this help you

regards

burningdan
08-14-2008, 07:58 AM
WOW! Thanks so much for your tips and tricks. you will have saved me 20 hours by the time the year is over.

as it turns out, I'd just gotten the solution about when you were replying -- the output directory's group was apache and its ownership was 755. I'd read it, saw that the script was running as apache, saw that apache showed up in the line of ownership and didn't pay enough attention to correlate that the output directory wasn't writable. d'oh.

but really - all three of those suggestions are awesome and going to improve my life.

thank you

dan

oesxyl
08-14-2008, 08:05 AM
WOW! Thanks so much for your tips and tricks. you will have saved me 20 hours by the time the year is over.

as it turns out, I'd just gotten the solution about when you were replying -- the output directory's group was apache and its ownership was 755. I'd read it, saw that the script was running as apache, saw that apache showed up in the line of ownership and didn't pay enough attention to correlate that the output directory wasn't writable. d'oh.

but really - all three of those suggestions are awesome and going to improve my life.

thank you

dan
you ar welcome, :)
you can find some guide/howto's/intro on this link:

http://www.tldp.org/

'bash advanced guide', if I'm not wrong, anyway worst a look over all index, :)

bash exit/code, I guess can be find in bash man page
best regards



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum