ssuperczynski
ssuperczynski

Reputation: 3416

Execute a shell command in PHP without waiting for the results

I have a problem when executing a shell command. The problem is that I would like to run a command exec('du -sh /var/www/backups/* > backups.log') but I would like to just press "START" and read backups.log later. Right now when I press the button I have to wait until it finishes, so the page waits until the script finishes.

Upvotes: 4

Views: 2047

Answers (2)

user1603136
user1603136

Reputation:

You can use AJAX for resolve this problem, no ? When the user click on start, execute your Php script. During that, you can do everything else.

Upvotes: 0

Mike Brant
Mike Brant

Reputation: 71384

Trying launching the process in the background by adding "&" like this:

exec('du -sh /var/www/backups/* > backups.log &');

Upvotes: 5

Related Questions