Question

I have an automated task that listens for a 7zip file to be received from a remote machine, and then extracts the archive. The process runs fine whenever I manually push the file from the remote machine. However, at a certain time of day several dozen machines are pushing files to my server, and about 8-9% of the files return the following error when 7zip tries to extract them:

7-Zip (A) [64] 9.20  Copyright (c) 1999-2010 Igor Pavlov  2010-11-18
p7zip Version 9.20 (locale=en_US.UTF-8,Utf16=on,HugeFiles=on,6 CPUs)

Processing archive: /home/pos/inbox/05730049_20140206.7z

Error: Can not open file as archive

When I go in later to extract them manually, there is no problem unzipping the archive:

7-Zip (A) [64] 9.20  Copyright (c) 1999-2010 Igor Pavlov  2010-11-18
p7zip Version 9.20 (locale=en_US.UTF-8,Utf16=on,HugeFiles=on,6 CPUs)

Processing archive: /data/pos/processed/05730013_20140206.7z

Extracting  file01.txt
Extracting  file02.txt
Extracting  file03.txt
Extracting  file04.txt
Extracting  file05.txt
Extracting  file06.txt
Extracting  file07.txt
Extracting  file08.txt
Extracting  file09.txt
Extracting  file10.txt

Everything is Ok

Files: 10
Size:       472129
Compressed: 16506

I'm pretty sure there is nothing wrong with the archive because (1) the script is the same on each remote machine and it only happens with 8-9% of the archives, and (2) when I extract it manually, it doesn't return the same error. Is there any way to make sure the file extracts properly on it's own?

The php code that extracts it is this:

function import_unzip($filename) {
  global $debug,$fail_type,$clientID,$location,$mode;

  ...

  if (!is_readable("/home/pos/inbox/$filename")) {
    $fail_type = 'NF';
    return false;
  } else {    
    //Unzip the file
    $cmd_res = exec("7za e -y -o/data/pos/$clientID$location /home/pos/inbox/$filename -p{$zip_passwd[$clientID]}",$output,$return_var);
    return $success;
  }
}

My first inclination is to put an error handling while loop around the 7z command and give it three or so tries, but I'm hoping there's a more elegant solution.

Was it helpful?

Solution

I looks like you have a race condition. Try the debug option in the comments.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top