Running lame from php

I am trying to run lame from a php script.

I tried this but no luck, I got nothing! 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'm on OSX and the final deployment will be on Linux. Do you have any better suggestions for automatic wav-> mp3 conversion? From php, should I execute a bash script that executes Lame?

+2


a source to share


4 answers


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 strings contained in the output file



$ result must be an integer result. 0 is usually successful,> = 1 is error (specific codes vary by application).

Part 2> and 1 will redirect STDERR to STDOUT ($ output) which is usually discarded. So if it's a bug, you should be able to see the error (hopefully).

If you get -1 to dump $ result, there is a fundamental problem because it is the wrong result code (it probably means exec is disabled or the process you are trying to start is restricted due to error permissions or such) ...

+4


a source


If you feel the need for a nicer way to work with lame

, I would recommend using the phplame wrapper. Install PHP LAME wrapper using Composer:



{
    "require": {
        "b-b3rn4rd/phplame": "dev-master"
    }
}

      

+3


a source


install error reporting and check if you can exec. By default, most systems do not allow this, it is a serious security responsibility. You must explicitly enable execs in php.ini.

0


a source


May be a problem $PATH

. Try giving the full path to the lame one, i.e. /usr/local/bin/lame

...

0


a source







All Articles