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
- Scaling
- Scales with input
- Instructions
- 25–153
- Plugin surface
- None
- Called by
- 1
Reads or writes the filesystem via fopen().
The body loops, so the work grows with what you pass in.
Executed per call on PHP 8.5, depending on the branch taken. The body compiles to 253.
Nothing here hands control to plugin code.
1 place in core call this, so the cost is paid more often than your own code shows.
What it touches
- filesystemfilesystem access
fopen()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.
| When | Instructions | Calls it makes |
|---|---|---|
$v_file == 0 | 25 | fopen(), ::PclZip(), ::PclZip() |
$v_file != 0 && $v_file_compressed == 0 | 42 | fopen(), uniqid(), gzopen(), fclose(), ::PclZip(), ::PclZip() |
$v_file != 0 && $v_file_compressed != 0 && $v_size == 0 | 60 | fopen(), uniqid(), gzopen(), filesize(), fclose(), gzclose(), filesize(), ::PclZip(), ::PclZip() |
$v_file != 0 && $v_file_compressed != 0 && $v_size == 0 && $v_file_compressed == 0 | 69 | fopen(), uniqid(), gzopen(), filesize(), fclose(), gzclose(), filesize(), fopen(), ::PclZip(), ::PclZip() |
$v_file != 0 && $v_file_compressed != 0 && $v_size == 0 && $v_result != 1 | 126 | fopen(), 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 == 0 | 144 | fopen(), 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 == 1 | 153 | fopen(), 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
| PHP | Compiled | Executed | Branches | Notes |
|---|---|---|---|---|
| 8.6-dev | 253 | 25–153 | 10 | |
| 8.5 | 253 | 25–153 | 10 | |
| 8.4 | 253 | 25–153 | 10 | |
| 8.3 | 253 | 25–153 | 10 | |
| 8.2 | 253 | 25–153 | 10 | |
| 8.1 | 253 | 25–153 | 10 | 2 fewer instructions than PHP 7.4 |
| 7.4 | 255 | 25–153 | 10 |
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.
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.