0

I wanted to start a backup process. To do that user initiate the process/task from php script.

Here is the script

<?php
    echo "starting";
    shell_exec("whoami sleep 10 whoami > /dev/null 2>&1 &"); //background it.
    //in place of backup start process i replaced with sleep just for testing
    echo "Backup started, you will get mail once backup is done.";
 ?>

I tried to background the process but it seems like the php script is running for 10 seconds. I don't want the php script to run for 10 sec(web browser loading till the end) so user don't have to wait for that long and echo response to end user as soon as I started any job.

What am I doing wrong here?

Question is unique

Another question is not at all with the solution(output to different place and background it). But here I used the solution already but the solution isn't working still. Not sure what am I doing wrong. So this should be considered as new question.

rram
  • 2,004
  • 5
  • 24
  • 37
  • Possible duplicate of [php exec command (or similar) to not wait for result](https://stackoverflow.com/questions/3819398/php-exec-command-or-similar-to-not-wait-for-result) – Michel Oct 25 '17 at 06:49
  • @Michel I am not asking for a new solution. I am following a known principal but it isn't working. That is the reason I am asking the question. – rram Oct 25 '17 at 06:52
  • @Michel Please check my edit about how my question is unique. – rram Oct 25 '17 at 07:00
  • 1
    Just tried your script on PHP7, Ubuntu 17.10 and it doesn't wait at all (capturing output shows that it's just erroring the command) – Nigel Ren Oct 25 '17 at 07:07
  • @NigelRen am using mac and php 5.6. Do you think this could be an issue? – rram Oct 25 '17 at 07:14

0 Answers0