views:

147

answers:

5

I am working with a form that allows me to upload files via a local folder and FTP. So I want to move files over ftp (which already works)

Because of performance reasons I chose this process to run in the background so I use nfcftpput (linux)

In CLI the following command works perfectly: ncftpput-b-u name -p password -P 1980 127.0.0.1 /upload/ /home/Downloads/upload.zip

(Knowing that the b-parameter triggers background process) But if I run it via PHP it does not work (without the-b parameter it does)

PHP code:

$cmd = "ncftpput -b -u name -p password -P 1980 127.0.0.1 /upload/ /home/Downloads/upload.zip";
$return = exec($cmd);
+1  A: 

Try one of the following:

1) Use the command $cmd = "ncftpput -b -u name -p password -P 1980 127.0.0.1 /upload/ /home/Downloads/upload.zip &"; (Notice the &)

2) Try php's proc_open function http://php.net/manual/en/function.proc-open.php

Obsidian
A: 

Try adding '&' at the end of command, this will fork it on linux level. Also try shell_exec(), if previous won't work.

Wojtek
A: 

On *nix platforms it is possible to start a process in background and return control to php using the & operator and output redirection. I've described it in this article.

Salman A
A: 

Take a look at pcntl_fork. This user note has information how to correctly spawn a background process. Note that the extension that provides this function might not be activated in your PHP installation.

Artefacto
A: 

The best working solution for me is the following code:

function executeBackgroundProces($command) {

    $command = $command . ' > /dev/null 2>&1 & echo $!';
    exec ( $command, $op );
    $pid = ( int ) $op [0];
    if ($pid != "")
        return $pid;

    return false;
}

The command I run is: "ls bashfile" The bash file contains commands like the upload and deletion of the original files separated by ; This works fine by me

Robijntje007