5

i'm using php in apache on CentOS. i'm need to serve users, that they can delete big files by click. trying to use shell_exec. but its not run in the background. it runs and make the user wait.

my command :

$D_command="rm -rf videos/'$Mdelete'";

shell_exec($D_command);

thanks!

Community
  • 1
  • 1
user692601
  • 107
  • 1
  • 3
  • 12

5 Answers5

4

ass & at the end of the command.

$D_command="nohup rm -rf videos/'$Mdelete' > /log/deletedfile.log 2>&1 &";
Book Of Zeus
  • 49,509
  • 18
  • 174
  • 171
3
$PID = shell_exec("nohup $Command 2> /dev/null & echo $!");

http://php.net/manual/en/function.shell-exec.php

Dave Lasley
  • 5,262
  • 1
  • 34
  • 37
0

Try this:

popen($D_command, 'r')
ehed
  • 804
  • 1
  • 8
  • 18
0

I know this is quite an old question, but I had the same issue, and this was the only working solution after trying and failing with exec,shell_exec, process_open:

$process = popen("nohup $D_command > /dev/null 2> /dev/null & echo $!", 'r');
$pid = fread($process, 32);
Tom Imrei
  • 1,514
  • 12
  • 16
0

Try running

rm -rf videos/'$Mdelete' &

using exec. The ampersand indicates to run to the background

Foo Bah
  • 25,660
  • 5
  • 55
  • 79
  • nohup has to be added at the beginning of the command. This tells the php interpreter to run the process in the background. Instead of returning the output of the command, it returns the process id – Dave Lasley Aug 28 '11 at 15:21
  • @user692601 did you try using `exec` or `shell_exec`? – Foo Bah Aug 30 '11 at 13:28