Loading background in PHP

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

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

In the CLI, the following command works just fine: ncftpput-bu name -p password -P 1980 127.0.0.1/upload//home/Downloads/upload.zip

(knowing that the b parameter starts the background process) But if I run it through PHP, it does not work (without the -b parameter)

PHP code:

$cmd = "ncftpput -b -u name -p password -P 1980 127.0.0.1 /upload/ /home/Downloads/upload.zip";
$return = exec($cmd);
+3
source share
4 answers

Try one of the following:

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

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

+1

'&' Linux. shell_exec(), .

0

:

function executeBackgroundProces($command) {

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

    return false;
}

, , : "ls bashfile" bash , , ;

0

Source: https://habr.com/ru/post/1746986/


All Articles