Darm0ka
Darm0ka

Reputation: 312

Abort php script

I successfully zip a folder through the following code:

$('#test').click(function(){
    $.ajax({
        method:'post',
        url:site+'/home/test',
        data:{item_name:item_name,ext:ext},
        success:function(result){}
    });
});

public function test(){
    $item_name=$this->input->post('item_name');
    $ext=$this->input->post('ext');
    shell_exec('cd zip_folder/; zip -r '.$item_name.'.'.$ext.' '. $item_name);
    echo '1';
}

But I have a problem when the folder is very large, like 1GB, it takes a lot to zip and I can't make more requests until the end of script. I want to give the possibility of being able to cancel the process using a cancel button. I already tried xhr.abort() but without success. Even when I press f5 the site stays in loading until the zip is complete. I would also like to know if pressing f5 is possible to cancel this script.

Upvotes: 0

Views: 98

Answers (1)

Gabriel Souto
Gabriel Souto

Reputation: 620

You can try get all the running process and identify the one zipping files and then kill the process. All with shell_exec.

Upvotes: 1

Related Questions