Page 1 of 1

ZipArchive not working, no errors

Posted: Wed Jul 22, 2015 9:58 am
by Skara
I'm trying to zip a (very large) set of files, but nothing happens and I can't seem to get any errors to return.

The following returns a single error, every time: #6, at the end.

Each file exists, it's readable, ZipArchive::addFile returns true, $zipArchive close()s without fail, and yet the final zip file isn't created.

What gives?

** Running this on Windows Server 2012 R2 as a local SAN, if that matters.

Code: Select all

//exceptions, throws ErrorException
set_error_handler('exception_error');

try {
    // Copy directory to temporary location
    rcopy($src_location,$tmp_location);

    // Initialize archive object
    $zipArchive = new ZipArchive();
    $zipArchive->open($archive_filename, ZipArchive::CREATE | ZipArchive::OVERWRITE);

    // Create recursive directory iterator
    $files = new RecursiveIteratorIterator(
        new RecursiveDirectoryIterator($tmp_location),
        RecursiveIteratorIterator::LEAVES_ONLY
    );

    foreach ($files as $name => $file) {
        // Skip directories (they would be added automatically)
        if (!$file->isDir()) {
            // Get real and relative path for current file
            $filePath = $file->getRealPath();
            $relativePath = substr($filePath, strlen($tmp_location) + 1);

            if (!file_exists($filePath)) {
                _log(1,'Uploading Archives [Compression Error #1]','File Not Found ['.$filePath.']');
                throw new Exception('Giving Up');
            }
            elseif (!is_readable($filePath)) {
                _log(1,'Uploading Archives [Compression Error #2]','File Not Readable ['.$filePath.']');
                throw new Exception('Giving Up');
            }
            else {
                // Add current file to archive
                if (!$zipArchive->addFile($filePath, $relativePath)) {
                    _log(1,'Uploading Archives [Compression Error #7]','File Not Added ['.$filePath.' | '.$relativePath.']');
                    throw new Exception('Giving Up');
                }
            }
        }
    }

    // Zip archive will be created only after closing object
    if (!$zipArchive->close()) {
        _log(1,'Uploading Archives [Compression Error #3]','Zip Not Created ['.$zipArchive->getStatusString().']');
    }
}
catch (ErrorException $e) {
    _log(1,'Uploading Archives [Copy/Compression Error #4]',(string)$e);
}
catch (Exception $e) {
    _log(1,'Uploading Archives [Copy/Compression Error #5]',(string)$e);
}
finally {
    // Clean Up Memory
    unset($files);
    unset($zipArchive);
}

// Final Check
if (!file_exists($archive_filename)) {
    _log(1,'Uploading Archives [Compression Error #6]','Error Creating Archive ['.$archive_filename.'] ('.$src_location.')');
}

Re: ZipArchive not working, no errors

Posted: Wed Jul 22, 2015 5:45 pm
by Weirdan
Are you sure the file does not get created, or you're just trusting file_exists() return value? file_exists() is affected by stat cache (you may need to call clearstatcache() before calling file_exists()). file_exists() also requires directory listing permissions on the folder that contains the file (something not every user has on some system directories like C:\Windows\Temp).

What is the return value of $zipArchive->open()?

Re: ZipArchive not working, no errors

Posted: Thu Jul 23, 2015 7:08 am
by Skara
Hm. I'll check the output of $zipArchive->open(), but the file definitely isn't created. I check in an explorer window for congruity, etc. It just isn't there. That's interesting about clearstatcache() though.

The script copies the directory to be zipped to the same directory as it's creating the zip file, so no issues with writing or reading.

Re: ZipArchive not working, no errors

Posted: Tue Jul 28, 2015 8:37 am
by Skara
Finally found time to get back around to this project. It kills resources, so it only runs at night, limiting my bugtesting abilities.

$zipArchive->open() returns true (no errors).

I truly can't figure out what's going on. There are no errors with any part of ZipArchive, and yet after it's finished the zip file simply isn't there.

Re: ZipArchive not working, no errors

Posted: Tue Jul 28, 2015 8:55 am
by Weirdan
The file could possibly be saved in a so-called virtual store (C:\Users\[User_name]\AppData\Local\VirtualStore\[Path])

Re: ZipArchive not working, no errors

Posted: Tue Jul 28, 2015 9:02 am
by Skara
Watching the script run...

The source directory is copied to a temporary directory "5.tmp/" at 5.12GB
Then 5.zip.a01612 is created. It begins at 0B, but fills up as the script runs... watching it reach 3GB... And then when it reaches completion (I'm assuming at ->close()), the file disappears. Poof.

[[ No idea about the a01612 extention, not my doing; that appears to be in the functionality of ZipArchive. ]]

Thoughts?

Re: ZipArchive not working, no errors

Posted: Tue Jul 28, 2015 9:04 am
by Skara
C:\Users\[User_name]\AppData\Local\VirtualStore\[Path]

VirtualStore doesn't exist.

Re: ZipArchive not working, no errors

Posted: Tue Jul 28, 2015 9:29 am
by Weirdan
Have you checked the windows event log?

Re: ZipArchive not working, no errors

Posted: Tue Jul 28, 2015 10:35 am
by Skara
Hm. I skimmed through it, but I don't see anything relevant from today. I'm not sure what I should be looking for, though.

Re: ZipArchive not working, no errors

Posted: Tue Jul 28, 2015 11:06 am
by Skara
I should add:

I gave up on ZipArchive once and tried using PharData to do the same thing with a .tar.gz file. No matter what I did, I kept getting thrown an exception that said it couldn't add a file "seek failed." Only found one other report of this error when trying to compress a large number of files. I wonder if there's not some weird permissions error going on, that PHP can read/write but somehow its extensions have issues? If that makes sense. Maybe it doesn't.

Re: ZipArchive not working, no errors

Posted: Wed Jul 29, 2015 9:56 am
by Skara
Blah. Giving up. I partially have PharData working now. Starting a new thread since I have an entirely new problem (probably).

Re: ZipArchive not working, no errors

Posted: Mon Aug 03, 2015 10:34 am
by Weirdan
Something I didn't know about zip: specification (ยง4.4.8) says size fields (both compressed and uncompressed) are 4 bytes long - meaning it does not support file sizes above 4gb. Are you trying to create files larger than that? Are other implementations (like winzip) able to compress your data?