PhpConcept
 
 

PclZip 2.8 - User Manual

 
 

Overview - Table Of Content - Downloads - What's New - FAQ

 
 
Optional Arguments
 
 

 

PCLZIP_OPT_TEMP_FILE_ON,
PCLZIP_OPT_TEMP_FILE_OFF,
PCLZIP_OPT_TEMP_FILE_THRESHOLD

Starting with release 2.7, PclZip is able to use temporary files to zip or extract files in archive to better support large files.

In most situation PclZIp will use "in memory" zip alorythm, which mean that PclZip will read all the file to archive, compress it and then write the result in the zip archive. By using temporary files PclZip will compress the file by reading small blocks (2048 bytes) and directly write the compressed block in a temporary file. Then PclZip add the temporary file in the archive and delete the temporary file.
With release 2.8, the same mecanism is used for extraction of files from a zip archive.

When adding (extracting) very large files in the archive, PclZip can reach the memory limitation configured with PHP ("memory_limit" value in php.ini), and fail to create the archive. By using temporary file, PclZip will have better chance to succeed. However using temporary file is less performant than doing compression in memory.

Starting with 2.7, PclZip will auto-sense the size of the file, and, depending on the configured value of "memory_limit", will decide to use temporary files or not. The following optional arguments allow the user to disable auto-sense and decide what method PclZip should use.

    • PCLZIP_OPT_ADD_TEMP_FILE_ON : instruct PclZip to use all the time temporary files to create the zip archive,
    • PCLZIP_OPT_ADD_TEMP_FILE_THRESHOLD, <size_in_megabytes> : instruct PclZip to use temporary files for files with size greater than <size_in_megabytes>,
    • PCLZIP_OPT_ADD_TEMP_FILE_OFF : instruct PclZip tu use all the time "in memory" compression to create the zip archive (same as PclZip 2.6 and earlier)

Sample using PCLZIP_OPT_TEMP_FILE_ON :

<?php
  
include_once('pclzip.lib.php');
  
$archive = new PclZip('archive.zip');
  
$v_list $archive->create('data/image-1.jpg,data/image-2.jpg',
                             
PCLZIP_OPT_REMOVE_PATH'data',
                             
PCLZIP_OPT_ADD_TEMP_FILE_ON);
  if (
$v_list == 0) {
    die(
"Error : ".$archive->errorInfo(true));
  }
?>

Sample using PCLZIP_OPT_TEMP_FILE_THRESHOLD :

<?php
  
include_once('pclzip.lib.php');
  
$archive = new PclZip('archive.zip');
  
$v_list $archive->create('data/image-1.jpg,data/image-2.jpg',
                             
PCLZIP_OPT_REMOVE_PATH'data',
                             
PCLZIP_OPT_TEMP_FILE_THRESHOLD10);
  if (
$v_list == 0) {
    die(
"Error : ".$archive->errorInfo(true));
  }
?>

Sample using PCLZIP_OPT_TEMP_FILE_OFF :

<?php
  
include_once('pclzip.lib.php');
  
ini_set('memory_limit''180M');
  
$archive = new PclZip('archive.zip');
  
$v_list $archive->create('data/image-1.jpg,data/image-2.jpg',
                             
PCLZIP_OPT_REMOVE_PATH'data',
                             
PCLZIP_OPT_TEMP_FILE_OFF);
  if (
$v_list == 0) {
    die(
"Error : ".$archive->errorInfo(true));
  }
?>

These arguments can be used with 'create()', 'add()', 'extract()' and 'extractByIndex()' methods.

Note that "PCLZIP_OPT_ADD_TEMP_FILE_ON", "PCLZIP_OPT_ADD_TEMP_FILE_THRESHOLD" and "PCLZIP_OPT_ADD_TEMP_FILE_OFF" are former attributes name that were replaced by these new names.

 

 

Member login - Stats
Copyright 2003 - PhpConcept

Powered by PcWeb