php:用户取消后的清理过程残留

I have a page where I get the user to download data that the server zips right away for them. This is how it looks:

createFilesList(); //  <---- creates a text list of files do be zipped

header('Content-Type: application/zip');
header('Content-disposition: attachment; filename="'.$downloadFilename.'');

$fp = popen('cat '.$fullListOfFiles.' | sudo -u myuser zip -@ -9 - ', 'r');

$bufsize = 8192;
$buff = '';
while( !feof($fp) ) 
{
    $buff = fread($fp, $bufsize);
    echo $buff;
}
pclose($fp);

doClean(); //  <----- deletes the list of files

The problem: If the user downloads the file, the clean-up works fine. However, if the user cancels the download, the list remains there uncleaned!

Failed solution from other posts: Other posts have suggested this solution:

ignore_user_abort(true);

While this works fine to cleanup, it introduces a new problem: If the user cancels, the zipping process continues. This wastes resources on the computer for no good reason.

How can I guarantee that the clean-up runs?

This should run everytime, even after aborting by user -> register_shutdown_function http://php.net/manual/en/function.register-shutdown-function.php

// register a shutdown cleanup
register_shutdown_function('doClean');

createFilesList(); //  <---- creates a text list of files do be zipped

header('Content-Type: application/zip');
header('Content-disposition: attachment; filename="'.$downloadFilename.'');

$fp = popen('cat '.$fullListOfFiles.' | sudo -u myuser zip -@ -9 - ', 'r');

$bufsize = 8192;
$buff = '';
while( !feof($fp) ) 
{
    $buff = fread($fp, $bufsize);
    echo $buff;
}
pclose($fp);

Never tried but maybe this could work : just use connection_aborted() to test before zipping.

createFilesList(); //  <---- creates a text list of files do be zipped

header('Content-Type: application/zip');
header('Content-disposition: attachment; filename="'.$downloadFilename.'');

if(0 ==connection_aborted())
{
    $fp = popen('cat '.$fullListOfFiles.' | sudo -u myuser zip -@ -9 - ', 'r');

    $bufsize = 8192;
    $buff = '';
    while( !feof($fp) ) 
    {
        $buff = fread($fp, $bufsize);
        echo $buff;
    }
    pclose($fp);
}


doClean(); //  <----- deletes the list of files