ExpressionEngine CMS
Open, Free, Amazing

Thread

This is an archived forum and the content is probably no longer relevant, but is provided here for posterity.

The active forums are here.

exec in PHP

June 16, 2009 1:48pm

Subscribe [6]
  • #1 / Jun 16, 2009 1:48pm

    Guntars

    16 posts

    Hi
    I have Debian Linux VPS
    For some reason function exec not works on my server, I can’t execute files, but when I type this function, and type print_r becomes an empty array.
    Then I try to put this

    if(function_exists(exec)){echo 'function exists';}
    else{echo 'function not exists';}


    Come back as function not exists
    Any ideas how to I can enable exec function, in php.in I can’t find anything about disable this function.

  • #2 / Jun 16, 2009 1:58pm

    jedd

    2089 posts

    It’ll be your safe_mode_exec_dir setting in your php.ini.

    If you don’t have a real machine, but are hosted instead, you may not have access to change this.

    Oh, do a phpinfo.php page and look for the two relevant settings: safe_mode (bool) and safe_mode_exec_dir (string)

  • #3 / Jun 16, 2009 2:10pm

    Guntars

    16 posts

    Here is my phpinfo Safe mode is off. Snything else need to check.

  • #4 / Jun 16, 2009 2:17pm

    jedd

    2089 posts

    So if you go down to this line:

    safe_mode_exec_dir          /usr/lib/php5/libexec         /usr/lib/php5/libexec

    You can see that you have safe_mode_exec_dir enabled, so only files located in that directory can be exec()‘d.

    If you have ssh access to that box, try copying some binary - /bin/ls for example - into there, and then do an exec (‘ls’) through PHP.

  • #5 / Jun 16, 2009 3:09pm

    Guntars

    16 posts

    When I copy to this directory it works, you recomend me leave as it is, and just, which functions need to execute copy here, or change the directory?

  • #6 / Jun 16, 2009 3:35pm

    jedd

    2089 posts

    When I copy to this directory it works

    Is that a confirmation or a follow-up question?

    , you recomend me leave as it is, and just, which functions need to execute copy here, or change the directory?

    You have a range of options.  Modify the PHP setting to allow you to run binaries from anywhere, or maintain a set of binaries (or symlinks to same) in that directory.

    On my own system I use the former, though a) I don’t use exec calls very often, b) I’m very cautious.  It’s probably one of those ‘if you have to ask how this works, then choose the safer option’.  My gut feel here is that you should proceed with maintaining the directory’s contents with binaries that you trust, and (obviously) retain the safe exec setting as it is.

  • #7 / Jun 16, 2009 4:23pm

    Guntars

    16 posts

    Thank’s a lot.
    I don’t use exec function often as well. That’s means If I need some exec files, just copy in current directory.

  • #8 / Jul 09, 2009 6:19am

    newbie boy

    88 posts

    i have the same problem with this…

    see, i’m hoping to run a ffmpeg on which i put on my safe_mode_exec_dir…

    but still doesn’t gives out an ouput…

    hope you could me guys…

    thanks…

  • #9 / Jul 09, 2009 9:42am

    newbie boy

    88 posts

    someone, guys?

  • #10 / Jul 09, 2009 9:46am

    Guntars

    16 posts

    Can you write bit more about your problem?

  • #11 / Jul 09, 2009 11:26am

    Flemming

    270 posts

    It might be worth looking at proc_open - it may not be disabled and allows similar functionality to exec!

    http://uk.php.net/manual/en/function.proc-open.php

  • #12 / Jul 09, 2009 11:37pm

    newbie boy

    88 posts

    i tried this code…

    if (function_exists(exec('ffmpeg -t 30 -acodec copy -i $inputfile $outputfile'))){
    
           echo 'function exists';
    
          } else {
    
              echo 'function not exists'; }

    and the output is always function not exists…

    appreciate every little help…

  • #13 / Jul 10, 2009 4:20am

    cahva

    662 posts

    if (function_exists('exec'))
    {
        exec('ffmpeg -t 30 -acodec copy -i $inputfile $outputfile')));
        echo 'function exists';
    
    } 
    else
    {
        echo 'function not exists';
    }

    You put the whole exec line to the function_exists function and thats why it didnt work.

    For the earlier posts, if safe_mode is disabled, it doesnt matter what safe_mode_exec_dir is. It works only in safe mode.

    In general, its better to use the whole path to the executable. Commands without path will only be executed if they are in /usr/bin/ (depending on OS used).

  • #14 / Jul 10, 2009 4:43am

    newbie boy

    88 posts

    cahva,

    yeah you’re right… it’s just for testing…

    but still this code won’t work…

    $inputfile     = $uploadData[$i]['file_name'];
    $outputfile = 'preview_' . $inputfile;
                        
    $result = exec('ffmpeg -t 30 -acodec copy -i $inputfile $outputfile');     
                        
    echo $result;

    still no ouput data…

  • #15 / Jul 10, 2009 5:29am

    cahva

    662 posts

    Well exec only return the last line so it can be that the last line is empty. Ofcourse you would still have something in the $outputfile.

    Try to use the full path to ffmpeg eg. /usr/bin/ffmpeg

    You could also try this:

    ob_start();
    $inputfile     = $uploadData[$i]['file_name'];
    $outputfile = 'preview_' . $inputfile;
                        
    passthru('/usr/bin/ffmpeg -t 30 -acodec copy -i $inputfile $outputfile');
    
    $out = ob_get_contents();
    ob_end_clean();
    
    echo $out;
.(JavaScript must be enabled to view this email address)

ExpressionEngine News!

#eecms, #events, #releases