wppaste
WordPress

PclZip::privReadEndCentralDir( $p_central_dir )

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

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_central_dir

Performance profile

How much work a call to PclZip::privReadEndCentralDir() 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 filesize().

Scaling
Scales with input

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

Instructions
31–160

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

Plugin surface
None

Nothing here hands control to plugin code.

Called by
6

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

What it touches

  • filesystemfilesystem accessfilesize()called directly

What one call costs · 25 distinct outcomes

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

WhenInstructionsCalls it makes
$v_size != false31filesize(), fseek(), ftell(), ::PclZip(), ::PclZip()
$v_size == false && !$v_size43filesize(), fseek(), ftell(), fread(), ::PclZip(), ::PclZip()
$v_size == false51–56filesize(), fseek(), ftell(), fseek(), ftell(), ::PclZip(), ::PclZip()
$v_size == false && !$v_size && !$v_pos && $v_pos == false62–63filesize(), fseek(), ftell(), fseek(), ftell(), ftell(), ::PclZip(), ::PclZip()
$v_size == false && !$v_size64filesize(), fseek(), ftell(), fread(), unpack()
$v_size == false && !$v_size71filesize(), fseek(), ftell(), fread(), unpack(), fread()
$v_size == false && !$v_size && !$v_pos && $v_pos != false73–74filesize(), fseek(), ftell(), fseek(), ftell(), ftell(), fread(), ::PclZip(), ::PclZip()
$v_size == false && !$v_size && $v_pos && $v_bytes == 1347093766 && $v_pos == false80–81filesize(), fseek(), ftell(), fseek(), ftell(), ftell(), fread(), ord(), ::PclZip(), ::PclZip()
$v_size == false && $v_size && $v_pos == false82–83filesize(), fseek(), ftell(), fseek(), ftell(), fread(), unpack(), ftell(), fread(), ::PclZip(), ::PclZip()
$v_size == false && !$v_size && $v_pos && $v_bytes == 1347093766 && $v_pos != false91–92filesize(), fseek(), ftell(), fseek(), ftell(), ftell(), fread(), ord(), fread(), ::PclZip(), ::PclZip()
$v_size == false && !$v_size && !$v_pos && $v_pos != false94–95filesize(), fseek(), ftell(), fseek(), ftell(), ftell(), fread(), unpack()
$v_size == false && $v_size && $v_pos == false94–96filesize(), fseek(), ftell(), fseek(), ftell(), fread(), unpack(), ftell(), fseek(), ftell(), ::PclZip(), ::PclZip()
13 further outcomes, up to 160 instructions
$v_size == false && !$v_size && !$v_pos && $v_pos != false101–102filesize(), fseek(), ftell(), fseek(), ftell(), ftell(), fread(), unpack(), fread()
$v_size == false && $v_size && $v_pos == false && !$v_pos101–103filesize(), fseek(), ftell(), fseek(), ftell(), fread(), unpack(), ftell(), fseek(), ftell(), ftell(), ::PclZip(), ::PclZip()
$v_size == false && $v_size && $v_pos == false103–104filesize(), fseek(), ftell(), fseek(), ftell(), fread(), unpack(), ftell(), fread(), unpack()
$v_size == false && $v_size && $v_pos == false110–111filesize(), fseek(), ftell(), fseek(), ftell(), fread(), unpack(), ftell(), fread(), unpack(), fread()
$v_size == false && !$v_size && $v_pos && $v_bytes == 1347093766 && $v_pos != false112–113filesize(), fseek(), ftell(), fseek(), ftell(), ftell(), fread(), ord(), fread(), unpack()
$v_size == false && $v_size && $v_pos == false && !$v_pos && $v_pos != false112–114filesize(), fseek(), ftell(), fseek(), ftell(), fread(), unpack(), ftell(), fseek(), ftell(), ftell(), fread(), ::PclZip(), ::PclZip()
$v_size == false && !$v_size && $v_pos && $v_bytes == 1347093766 && $v_pos != false119–120filesize(), fseek(), ftell(), fseek(), ftell(), ftell(), fread(), ord(), fread(), unpack(), fread()
$v_size == false && $v_size && $v_pos == false && $v_pos && $v_bytes == 1347093766119–121filesize(), fseek(), ftell(), fseek(), ftell(), fread(), unpack(), ftell(), fseek(), ftell(), ftell(), fread(), ord(), ::PclZip(), ::PclZip()
$v_size == false && $v_size && $v_pos == false && $v_pos && $v_bytes == 1347093766 && $v_pos != false130–132filesize(), fseek(), ftell(), fseek(), ftell(), fread(), unpack(), ftell(), fseek(), ftell(), ftell(), fread(), ord(), fread(), ::PclZip(), ::PclZip()
$v_size == false && $v_size && $v_pos == false && !$v_pos && $v_pos != false133–135filesize(), fseek(), ftell(), fseek(), ftell(), fread(), unpack(), ftell(), fseek(), ftell(), ftell(), fread(), unpack()
$v_size == false && $v_size && $v_pos == false && !$v_pos && $v_pos != false140–142filesize(), fseek(), ftell(), fseek(), ftell(), fread(), unpack(), ftell(), fseek(), ftell(), ftell(), fread(), unpack(), fread()
$v_size == false && $v_size && $v_pos == false && $v_pos && $v_bytes == 1347093766 && $v_pos != false151–153filesize(), fseek(), ftell(), fseek(), ftell(), fread(), unpack(), ftell(), fseek(), ftell(), ftell(), fread(), ord(), fread(), unpack()
$v_size == false && $v_size && $v_pos == false && $v_pos && $v_bytes == 1347093766 && $v_pos != false158–160filesize(), fseek(), ftell(), fseek(), ftell(), fread(), unpack(), ftell(), fseek(), ftell(), ftell(), fread(), ord(), fread(), unpack(), fread()

Across PHP versions

PHPCompiledExecutedBranchesNotes
8.6-dev21431–16012
8.521431–16012
8.421431–16012
8.321431–16012
8.221431–16012
8.121431–160121 fewer instruction than PHP 7.4
7.421531–16112

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 · 2

Used by · 6

Source code

  function privReadEndCentralDir(&$p_central_dir)  {    $v_result=1;     // ----- Go to the end of the zip file    $v_size = filesize($this->zipname);    @fseek($this->zip_fd, $v_size);    if (@ftell($this->zip_fd) != $v_size)    {      // ----- Error log      PclZip::privErrorLog(PCLZIP_ERR_BAD_FORMAT, 'Unable to go to the end of the archive \''.$this->zipname.'\'');       // ----- Return      return PclZip::errorCode();    }     // ----- First try : look if this is an archive with no commentaries (most of the time)    // in this case the end of central dir is at 22 bytes of the file end    $v_found = 0;    if ($v_size > 26) {      @fseek($this->zip_fd, $v_size-22);      if (($v_pos = @ftell($this->zip_fd)) != ($v_size-22))      {        // ----- Error log        PclZip::privErrorLog(PCLZIP_ERR_BAD_FORMAT, 'Unable to seek back to the middle of the archive \''.$this->zipname.'\'');         // ----- Return        return PclZip::errorCode();      }       // ----- Read for bytes      $v_binary_data = @fread($this->zip_fd, 4);      $v_data = @unpack('Vid', $v_binary_data);       // ----- Check signature      if ($v_data['id'] == 0x06054b50) {        $v_found = 1;      }       $v_pos = ftell($this->zip_fd);    }     // ----- Go back to the maximum possible size of the Central Dir End Record    if (!$v_found) {      $v_maximum_size = 65557; // 0xFFFF + 22;      if ($v_maximum_size > $v_size)        $v_maximum_size = $v_size;      @fseek($this->zip_fd, $v_size-$v_maximum_size);      if (@ftell($this->zip_fd) != ($v_size-$v_maximum_size))      {        // ----- Error log        PclZip::privErrorLog(PCLZIP_ERR_BAD_FORMAT, 'Unable to seek back to the middle of the archive \''.$this->zipname.'\'');         // ----- Return        return PclZip::errorCode();      }       // ----- Read byte per byte in order to find the signature      $v_pos = ftell($this->zip_fd);      $v_bytes = 0x00000000;      while ($v_pos < $v_size)      {        // ----- Read a byte        $v_byte = @fread($this->zip_fd, 1);         // -----  Add the byte        //$v_bytes = ($v_bytes << 8) | ord($v_byte);        // Note we mask the old value down such that once shifted we can never end up with more than a 32bit number        // Otherwise on systems where we have 64bit integers the check below for the magic number will fail.        $v_bytes = ( ($v_bytes & 0xFFFFFF) << 8) | ord($v_byte);         // ----- Compare the bytes        if ($v_bytes == 0x504b0506)        {          $v_pos++;          break;        }         $v_pos++;      }

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.