PclZip::privAdd( $p_filedescr_list, $p_result_list, $p_options )
- Source
wp-admin/includes/class-pclzip.php:2164
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_list$p_result_list$p_options
Performance profile
How much work a call to PclZip::privAdd() 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
- 15–151
- Plugin surface
- None
- Called by
- 1
Reads or writes the filesystem via is_file().
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 276.
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
is_file()called directly
What one call costs · 9 distinct outcomes
One number would be a lie: the work depends on which branch runs. These are every distinct cost PclZip::privAdd() can have, taken from its control-flow graph on PHP 8.5.
| When | Instructions | Calls it makes |
|---|---|---|
!is_file() | 15 | is_file(), ->privCreate() |
is_file() | 21 | is_file(), filesize(), ->privCreate() |
is_file() && $v_result != 1 | 25 | is_file(), filesize(), ->privDisableMagicQuotes(), ->privOpenFd(), ->privSwapBackMagicQuotes() |
is_file() && $v_result == 1 && $v_result != 1 | 34 | is_file(), filesize(), ->privDisableMagicQuotes(), ->privOpenFd(), ->privReadEndCentralDir(), ->privCloseFd(), ->privSwapBackMagicQuotes() |
is_file() && $v_result == 1 && $v_zip_temp_fd == 0 | 64 | is_file(), filesize(), ->privDisableMagicQuotes(), ->privOpenFd(), ->privReadEndCentralDir(), rewind(), uniqid(), fopen(), ->privCloseFd(), ->privSwapBackMagicQuotes(), ::PclZip(), ::PclZip() |
is_file() && $v_result == 1 && $v_zip_temp_fd != 0 && $v_size == 0 && $v_result != 1 | 80 | is_file(), filesize(), ->privDisableMagicQuotes(), ->privOpenFd(), ->privReadEndCentralDir(), rewind(), uniqid(), fopen(), ->privAddFileList(), fclose(), ->privCloseFd(), unlink(), ->privSwapBackMagicQuotes() |
is_file() && $v_result == 1 && $v_zip_temp_fd != 0 && $v_size == 0 && $i && $v_result != 1 | 109 | is_file(), filesize(), ->privDisableMagicQuotes(), ->privOpenFd(), ->privReadEndCentralDir(), rewind(), uniqid(), fopen(), ->privAddFileList(), ftell(), ->privWriteCentralFileHeader(), fclose(), ->privCloseFd(), unlink(), ->privSwapBackMagicQuotes() |
is_file() && $v_result == 1 && $v_zip_temp_fd != 0 && $v_size == 0 && !$i && $v_result != 1 | 117–128 | is_file(), filesize(), ->privDisableMagicQuotes(), ->privOpenFd(), ->privReadEndCentralDir(), rewind(), uniqid(), fopen(), ->privAddFileList(), ftell(), ftell(), ->privWriteCentralHeader(), ->privSwapBackMagicQuotes() |
is_file() && $v_result == 1 && $v_zip_temp_fd != 0 && $v_size == 0 && !$i | 140–151 | is_file(), filesize(), ->privDisableMagicQuotes(), ->privOpenFd(), ->privReadEndCentralDir(), rewind(), uniqid(), fopen(), ->privAddFileList(), ftell(), ftell(), ->privWriteCentralHeader(), ->privCloseFd(), fclose(), ->privSwapBackMagicQuotes(), unlink(), PclZipUtilRename() |
Across PHP versions
| PHP | Compiled | Executed | Branches | Notes |
|---|---|---|---|---|
| 8.6-dev | 276 | 15–151 | 17 | |
| 8.5 | 276 | 15–151 | 17 | |
| 8.4 | 276 | 15–151 | 17 | |
| 8.3 | 276 | 15–151 | 17 | |
| 8.2 | 276 | 15–151 | 17 | |
| 8.1 | 276 | 15–151 | 17 | 1 fewer instruction than PHP 7.4 |
| 7.4 | 277 | 15–150 | 17 |
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 · 13
- PclZipUtilRename()
- PclZip::privCreate()
- PclZip::privDisableMagicQuotes()
- PclZip::privOpenFd()
- PclZip::privSwapBackMagicQuotes()
- PclZip::privReadEndCentralDir()
- PclZip::privCloseFd()
- PclZip::privErrorLog()
- PclZip::errorCode()
- PclZip::privAddFileList()
- PclZip::privWriteCentralFileHeader()
- PclZip::privConvertHeader2FileInfo()
Show all 13
Used by · 1
Source code
function privAdd($p_filedescr_list, &$p_result_list, &$p_options) { $v_result=1; $v_list_detail = array(); // ----- Look if the archive exists or is empty if ((!is_file($this->zipname)) || (filesize($this->zipname) == 0)) { // ----- Do a create $v_result = $this->privCreate($p_filedescr_list, $p_result_list, $p_options); // ----- Return return $v_result; } // ----- Magic quotes trick $this->privDisableMagicQuotes(); // ----- Open the zip file if (($v_result=$this->privOpenFd('rb')) != 1) { // ----- Magic quotes trick $this->privSwapBackMagicQuotes(); // ----- Return return $v_result; } // ----- Read the central directory information $v_central_dir = array(); if (($v_result = $this->privReadEndCentralDir($v_central_dir)) != 1) { $this->privCloseFd(); $this->privSwapBackMagicQuotes(); return $v_result; } // ----- Go to beginning of File @rewind($this->zip_fd); // ----- Creates a temporary file $v_zip_temp_name = PCLZIP_TEMPORARY_DIR.uniqid('pclzip-').'.tmp'; // ----- Open the temporary file in write mode if (($v_zip_temp_fd = @fopen($v_zip_temp_name, 'wb')) == 0) { $this->privCloseFd(); $this->privSwapBackMagicQuotes(); PclZip::privErrorLog(PCLZIP_ERR_READ_OPEN_FAIL, 'Unable to open temporary file \''.$v_zip_temp_name.'\' in binary write mode'); // ----- Return return PclZip::errorCode(); } // ----- Copy the files from the archive to the temporary file // TBC : Here I should better append the file and go back to erase the central dir $v_size = $v_central_dir['offset']; while ($v_size != 0) { $v_read_size = ($v_size < PCLZIP_READ_BLOCK_SIZE ? $v_size : PCLZIP_READ_BLOCK_SIZE); $v_buffer = fread($this->zip_fd, $v_read_size); @fwrite($v_zip_temp_fd, $v_buffer, $v_read_size); $v_size -= $v_read_size; } // ----- Swap the file descriptor // Here is a trick : I swap the temporary fd with the zip fd, in order to use // the following methods on the temporary fil and not the real archive $v_swap = $this->zip_fd; $this->zip_fd = $v_zip_temp_fd; $v_zip_temp_fd = $v_swap; // ----- Add the files $v_header_list = array(); if (($v_result = $this->privAddFileList($p_filedescr_list, $v_header_list, $p_options)) != 1) { fclose($v_zip_temp_fd); $this->privCloseFd(); @unlink($v_zip_temp_name);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.