wppaste
WordPress

PclZip::privAddFileUsingTempFile( $p_filedescr, $p_header, $p_options )

Source
wp-admin/includes/class-pclzip.php:2806

Compatibility

WordPress
core
PHP
7.4–8.6-dev
  • 6.7.7
  • 6.8.8
  • 6.9.7
  • 7.0.4
  • 7.1.0

Present in every tracked release (6.7.7 to 7.1.0), and compiles on PHP 7.4 through 8.6-dev.

Parameters

$p_filedescr
$p_header
$p_options

Performance profile

How much work a call to PclZip::privAddFileUsingTempFile() does, and what it touches: the algorithmic scaling, the Zend instruction count per call across PHP versions, the hooks it hands control to, and the core code that calls it. Measured from the compiled opcodes, not a stopwatch, so every number is identical on any machine running the same PHP version, and every function in core is ranked by cost.

Cost class
Heavy

Reads or writes the filesystem via fopen().

Scaling
Scales with input

The body loops, so the work grows with what you pass in.

Instructions
25–153

Executed per call on PHP 8.5, depending on the branch taken. The body compiles to 253.

Plugin surface
None

Nothing here hands control to plugin code.

Called by
1

1 place in core call this, so the cost is paid more often than your own code shows.

What it touches

  • filesystemfilesystem accessfopen()called directly

What one call costs · 7 distinct outcomes

One number would be a lie: the work depends on which branch runs. These are every distinct cost PclZip::privAddFileUsingTempFile() can have, taken from its control-flow graph on PHP 8.5.

WhenInstructionsCalls it makes
$v_file == 025fopen(), ::PclZip(), ::PclZip()
$v_file != 0 && $v_file_compressed == 042fopen(), uniqid(), gzopen(), fclose(), ::PclZip(), ::PclZip()
$v_file != 0 && $v_file_compressed != 0 && $v_size == 060fopen(), uniqid(), gzopen(), filesize(), fclose(), gzclose(), filesize(), ::PclZip(), ::PclZip()
$v_file != 0 && $v_file_compressed != 0 && $v_size == 0 && $v_file_compressed == 069fopen(), uniqid(), gzopen(), filesize(), fclose(), gzclose(), filesize(), fopen(), ::PclZip(), ::PclZip()
$v_file != 0 && $v_file_compressed != 0 && $v_size == 0 && $v_result != 1126fopen(), uniqid(), gzopen(), filesize(), fclose(), gzclose(), filesize(), fopen(), fread(), unpack(), bin2hex(), filesize(), fseek(), fread(), unpack(), ord(), filesize(), fclose(), ->privWriteFileHeader()
$v_file != 0 && $v_file_compressed != 0 && $v_size == 0 && $v_result == 1 && $v_file_compressed == 0144fopen(), uniqid(), gzopen(), filesize(), fclose(), gzclose(), filesize(), fopen(), fread(), unpack(), bin2hex(), filesize(), fseek(), fread(), unpack(), ord(), filesize(), fclose(), ->privWriteFileHeader(), fopen(), ::PclZip(), ::PclZip()
$v_file != 0 && $v_file_compressed != 0 && $v_size == 0 && $v_result == 1153fopen(), uniqid(), gzopen(), filesize(), fclose(), gzclose(), filesize(), fopen(), fread(), unpack(), bin2hex(), filesize(), fseek(), fread(), unpack(), ord(), filesize(), fclose(), ->privWriteFileHeader(), fopen(), fseek(), fclose(), unlink()

Across PHP versions

PHPCompiledExecutedBranchesNotes
8.6-dev25325–15310
8.525325–15310
8.425325–15310
8.325325–15310
8.225325–15310
8.125325–153102 fewer instructions than PHP 7.4
7.425525–15310

An instruction is not a fixed amount of time, so a matching count is not necessarily the same speed; what it rules out is a difference in the work itself.

Uses · 4

Used by · 1

Source code

  function privAddFileUsingTempFile($p_filedescr, &$p_header, &$p_options)  {    $v_result=PCLZIP_ERR_NO_ERROR;     // ----- Working variable    $p_filename = $p_filedescr['filename'];      // ----- Open the source file    if (($v_file = @fopen($p_filename, "rb")) == 0) {      PclZip::privErrorLog(PCLZIP_ERR_READ_OPEN_FAIL, "Unable to open file '$p_filename' in binary read mode");      return PclZip::errorCode();    }     // ----- Creates a compressed temporary file    $v_gzip_temp_name = PCLZIP_TEMPORARY_DIR.uniqid('pclzip-').'.gz';    if (($v_file_compressed = @gzopen($v_gzip_temp_name, "wb")) == 0) {      fclose($v_file);      PclZip::privErrorLog(PCLZIP_ERR_WRITE_OPEN_FAIL, 'Unable to open temporary file \''.$v_gzip_temp_name.'\' in binary write mode');      return PclZip::errorCode();    }     // ----- Read the file by PCLZIP_READ_BLOCK_SIZE octets blocks    $v_size = filesize($p_filename);    while ($v_size != 0) {      $v_read_size = ($v_size < PCLZIP_READ_BLOCK_SIZE ? $v_size : PCLZIP_READ_BLOCK_SIZE);      $v_buffer = @fread($v_file, $v_read_size);      //$v_binary_data = pack('a'.$v_read_size, $v_buffer);      @gzputs($v_file_compressed, $v_buffer, $v_read_size);      $v_size -= $v_read_size;    }     // ----- Close the file    @fclose($v_file);    @gzclose($v_file_compressed);     // ----- Check the minimum file size    if (filesize($v_gzip_temp_name) < 18) {      PclZip::privErrorLog(PCLZIP_ERR_BAD_FORMAT, 'gzip temporary file \''.$v_gzip_temp_name.'\' has invalid filesize - should be minimum 18 bytes');      return PclZip::errorCode();    }     // ----- Extract the compressed attributes    if (($v_file_compressed = @fopen($v_gzip_temp_name, "rb")) == 0) {      PclZip::privErrorLog(PCLZIP_ERR_READ_OPEN_FAIL, 'Unable to open temporary file \''.$v_gzip_temp_name.'\' in binary read mode');      return PclZip::errorCode();    }     // ----- Read the gzip file header    $v_binary_data = @fread($v_file_compressed, 10);    $v_data_header = unpack('a1id1/a1id2/a1cm/a1flag/Vmtime/a1xfl/a1os', $v_binary_data);     // ----- Check some parameters    $v_data_header['os'] = bin2hex($v_data_header['os']);     // ----- Read the gzip file footer    @fseek($v_file_compressed, filesize($v_gzip_temp_name)-8);    $v_binary_data = @fread($v_file_compressed, 8);    $v_data_footer = unpack('Vcrc/Vcompressed_size', $v_binary_data);     // ----- Set the attributes    $p_header['compression'] = ord($v_data_header['cm']);    //$p_header['mtime'] = $v_data_header['mtime'];    $p_header['crc'] = $v_data_footer['crc'];    $p_header['compressed_size'] = filesize($v_gzip_temp_name)-18;     // ----- Close the file    @fclose($v_file_compressed);     // ----- Call the header generation    if (($v_result = $this->privWriteFileHeader($p_header)) != 1) {      return $v_result;    }     // ----- Add the compressed data    if (($v_file_compressed = @fopen($v_gzip_temp_name, "rb")) == 0)    {      PclZip::privErrorLog(PCLZIP_ERR_READ_OPEN_FAIL, 'Unable to open temporary file \''.$v_gzip_temp_name.'\' in binary read mode');      return PclZip::errorCode();    }

Changelog

Unchanged from 6.7.7 through 7.1.0.

  1. 6.7.7
  2. 6.8.8
  3. 6.9.7
  4. 7.0.4
  5. 7.1.0

Signature, return type and hooks compared across 5 parsed releases.

About this page

Parsed data
Generated from the wordpress-develop 7.1.0 tag, from src/wp-admin/includes/class-pclzip.php, and regenerated for each WordPress release so it tracks the code rather than a snapshot of it.
Corrections
Something wrong on this page? Report it and it gets fixed in the next regeneration.