2

I am trying to run lame from a php script.

I have tried these, but no luck, I don't get anything returned! Any ideas?

system('lame', $returnarr);
system('lame --help', $returnarr);
exec('lame', $returnarr);
passthru('lame', $returnarr);

even this one returns nothing:

exec('which lame', $returnarr);

I am on OSX and final deployment will be on Linux. Do you have better suggestions for an automated wav->mp3 conversion? From php, should I execute a bash script that executes Lame?

gok
  • 1,137
  • 1
  • 9
  • 30
  • what have you done to debug so far? Is there any output or error messages from any of these calls? Hard to say what to do if we don't know what you've done and what the results are/were. – Zak May 17 '10 at 17:23
  • I am getting nothing returned: print_r($returnarr); result: Array ( ) – gok May 17 '10 at 17:25

4 Answers4

4

Try something like this:

$output = array();
$result = -1;
exec('`/usr/bin/which lame` --help 2>&1', $output, $result);
var_dump($output, $result);

$output should be an array of lines contained in the output

$result should be an integer result code. 0 is typically success, >=1 is an error (specific codes are application dependant).

The 2>&1 part will redirect STDERR to STDOUT ($output) which would normally be dropped. So if it's erroring out, you should be able to see the error (hopefully).

If you get -1 for the dump of $result, there's a fundimental problem, because that's not a valid result code (it likely means that exec is disabled, or the process you're trying to run is restricted because of permissions errors or the such)...

ircmaxell
  • 163,128
  • 34
  • 264
  • 314
  • thanks a lot! it's strange that i can't get "which" working but lame works with full path. – gok May 17 '10 at 17:54
3

If you feel a need for more convenient way to work with lame, I would recommend to use phplame wrapper. Install PHP LAME wrapper using Composer:

{
    "require": {
        "b-b3rn4rd/phplame": "dev-master"
    }
}
b.b3rn4rd
  • 8,494
  • 2
  • 45
  • 57
0

set error reporting on and check if you can do exec's. By default most systems wont allow it, it's a serious security liability. You've got to explicitly allow execs in php.ini.

mhughes
  • 630
  • 3
  • 11
  • Error reporting is set to: E_ALL & ~E_STRICT, safe mode is off, disable_functions variable is empty, I don't understand why there are no errors and nothing is returned. – gok May 17 '10 at 17:30
0

Might be a $PATH problem. Try specifying the full path to lame, ie. /usr/local/bin/lame.

Annika Backstrom
  • 13,937
  • 6
  • 46
  • 52