im creating sort of system to copy files via web interface on my linux machine.

What i have is a bash script, php page and html page which is making an AJAX request to PHP page.

So here is an example of data flow in this system

HTML Page Form With AJAX -> PHP Script -> exec('./copy.sh '.$_REQUEST['folder'].' '.$_REQUEST['target'].'', $Output, $Result); echo end($Output); -> HTML Page Status div

Here is PHP part of Exec function:

exec('./copy.sh '.$_REQUEST['folder'].' '.$_REQUEST['target'].'', $Output, $Result); 
echo end($Output);

Here is my copy.sh

InitialDir="$(cd "$(dirname "${BASH_SOURCE[0]}" )" && pwd )"
cd "${InitialDir}"
rsync -a ${Folder} ${TargetDir} && echo "Complete!"

The thing is, i want to add progressbar to this operation, and it works with this code:

var url = "/copy.php";
    type: "POST",
    url: url,
    data: {folder: Folder, target: TargetFolder},
    success: function(data)


    window.location = '/';
}, 9000);

        step: function(now, fx) {
            if(fx.prop == 'width') {
                $(this).html(Math.round(now * 100) / 100 + '%');

But here is coming a problem, AJAX woks perfectly, php script works with no problems, but the thing is, even if files copied faster than 9 seconds (progressbar animation time), the overlay is still on, but sometimes files will be copied longer than 9 seconds.

So what im asking about is:

  1. Is it possible to somehow monitor copy progress with php + ajax (not mandatory)
  2. Is it possible to make AJAX close window even if its 4s left to animate progressbar, but received "Completed!" response from bash
  3. if non of the above mentioned possible, what else can i do?

P.S. Here is a small description of what im trying to achieve:

AJAX to PHP -> Execute Bash File -> Wait For Response -> Is Completed?
                                           ^            |
                                           |            -> Yes -> Close Modal Window Overlay
                                           |            |
                                           |            -> No -> |
                                           |                     |
2014/10/15 07:44
  • php
  • bash
  • ajax
  • javascript
  • 点赞
  • 收藏
  • 回答