exec() a php file

Discussion in 'PHP' started by cesarcesar, Mar 17, 2009.

  1. #1
    I'm trying to call a PHP page to run when called from another page. To do this it seems i have to use the exec() function. The code would go something like
    
    // set pathing
    $file = 'TEXT_small.m4v';
    $localfile = '/user/dac420/incoming/'.$file;
    $remotefolder = '/user/dac420/outgoing/';
    
    // exec the file and pass vars. transfer.php for this example just echo's Hi to the motherboard.
    exec('php transfer.php '.$localfile.' '.$remotefolder.' > '.$file.' &', $output, $result);
    print_r($output);
    print_r($result);
    
    Code (markup):
    Running this code and few variations of it give me either empty $result and $output vars or this
    
        [0] => Status: 404
        [1] => Content-type: text/html
        [2] => X-Powered-By: PHP/4.3.9
        [3] => 
        [4] => No input file specified.
    
    Code (markup):
    I have Googled "php exec" (and others) but I have come up with few reference. If someone can shed some light on this function or tell me where im wrong in my code i would appreciate it. Thanks.
     
    cesarcesar, Mar 17, 2009 IP
  2. shallowink

    shallowink Well-Known Member

    Messages:
    1,218
    Likes Received:
    64
    Best Answers:
    2
    Trophy Points:
    150
    #2
    Just out of curiosity, how are you processing the parameters sent to transfer.php ?
     
    shallowink, Mar 17, 2009 IP
  3. cesarcesar

    cesarcesar Peon

    Messages:
    188
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Using this part of the code. the path are the arguments
     
    cesarcesar, Mar 17, 2009 IP
  4. shallowink

    shallowink Well-Known Member

    Messages:
    1,218
    Likes Received:
    64
    Best Answers:
    2
    Trophy Points:
    150
    #4
    not what I was after. When transfer.php is called, how are catching the args inside that script. (its the part I can't see) If I'm not mistaken, by calling exec you are basically calling PHP as if from the command line. You should be using $argv or $argc, can't remember which.
     
    shallowink, Mar 17, 2009 IP
  5. SmallPotatoes

    SmallPotatoes Peon

    Messages:
    1,321
    Likes Received:
    41
    Best Answers:
    0
    Trophy Points:
    0
    #5
    Why not just use "include()"?
     
    SmallPotatoes, Mar 17, 2009 IP
  6. shallowink

    shallowink Well-Known Member

    Messages:
    1,218
    Likes Received:
    64
    Best Answers:
    2
    Trophy Points:
    150
    #6
    i was asking the same thing to myself. the variables are right there.....
     
    shallowink, Mar 17, 2009 IP
  7. cesarcesar

    cesarcesar Peon

    Messages:
    188
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #7
    Include/Require will not work. I should have explained better. The page im calling via exec() is transferring 1G file between two servers. If this file is include()'d, the page will hang white until the transfer is complete. Therefor i need to create a separate php process to run in the background. This way once the transfer is started, the user can continue with their browsing without waiting.

    The way to do this is with exec(). I just need to know how i went wrong. I think its pathing. Fu*^ing pathing every time! But maybe someone can help. Thanks.
     
    cesarcesar, Mar 18, 2009 IP
  8. shallowink

    shallowink Well-Known Member

    Messages:
    1,218
    Likes Received:
    64
    Best Answers:
    2
    Trophy Points:
    150
    #8
    Well, if anyone can help you, you will probably need to show at least a little bit of the transfer.php file. Cause from what you have shown, it all looks right. If transfer.php is looking at the Server Env for the input file, it will never find it.
     
    shallowink, Mar 18, 2009 IP
  9. SmallPotatoes

    SmallPotatoes Peon

    Messages:
    1,321
    Likes Received:
    41
    Best Answers:
    0
    Trophy Points:
    0
    #9
    exec() doesn't create a background process unless you redirect stdout, in which case you will lose control of the child process. If you fork without hanging around to babysit the child process, it may run indefinitely. Do this enough times and you will bork up your server. Since your initial process is time-limited by your PHP settings, ideally you would fork off a new controller process with its own more generous time limit that in turn forks off a worker process, waiting for SIGCHILD and doing something useful if it doesn't arrive eventually.
     
    SmallPotatoes, Mar 18, 2009 IP