简体   繁体   中英

How do I get the progress of an rsync run by a php exec command

I have a shell script (rsync.sh) with an rsync command in it:

rsync -rtlv --password-file=/path/to/password/file/file.txt --bwlimit=5000 /local/root/path/$1 username@remoteserver::remote/root/path/$2

I then run that from PHP (rsync.php) with an exec command:

exec('/path/to/shell/script/rsync.sh local/specific/path/ remote/specific/path/', $progress, $errors);

This all works fine. I get the progress once it's finished and I parse it. So far I've only been testing on a few smaller files. However, once this is put into production I am expecting this to be done on several large files that will take over an hour to finish. I would like to be able to view the progress as it's happening. If I put the --progress flag in there I'm not sure exactly how I'll get the progress back through the exec. Any ideas?

I think I'll have to make the exec asynchronous and somehow post the progress to a database where it can be collected and displayed.

You can't. The PHP exec() function does not return until the command completes.

This is really not a very good task for PHP — web servers generally do not cope well with PHP scripts (and, hence, web requests) that take hours to complete. That being said, you will be able to get closer to the intended behavior using the proc_open() family of functions, which allow you to start a process that runs in parallel with a PHP script.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM