wppaste
WordPress

PclZip::privReadCentralFileHeader( $p_header )

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

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_header

Performance profile

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

Scaling
Constant

No loop in the body: the same number of instructions runs whatever you pass in.

Instructions
25–109

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

Plugin surface
None

Nothing here hands control to plugin code.

Called by
3

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

What it touches

  • filesystemfilesystem accessfread()called directly

What one call costs · 6 distinct outcomes

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

WhenInstructionsCalls it makes
always25fread(), unpack(), ::PclZip(), ::PclZip()
always40fread(), unpack(), fread(), ::PclZip(), ::PclZip()
always86–88fread(), unpack(), fread(), unpack(), mktime()
always93–95fread(), unpack(), fread(), unpack(), fread(), mktime()
always100–102fread(), unpack(), fread(), unpack(), fread(), fread(), mktime()
always107–109fread(), unpack(), fread(), unpack(), fread(), fread(), fread(), mktime()

Across PHP versions

PHPCompiledExecutedBranchesNotes
8.6-dev13725–1096
8.513725–1096
8.413725–10963 fewer instructions than PHP 8.3
8.314025–1126
8.214025–1126
8.114025–1126
7.414025–1126

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

Source code

  function privReadCentralFileHeader(&$p_header)  {    $v_result=1;     // ----- Read the 4 bytes signature    $v_binary_data = @fread($this->zip_fd, 4);    $v_data = unpack('Vid', $v_binary_data);     // ----- Check signature    if ($v_data['id'] != 0x02014b50)    {       // ----- Error log      PclZip::privErrorLog(PCLZIP_ERR_BAD_FORMAT, 'Invalid archive structure');       // ----- Return      return PclZip::errorCode();    }     // ----- Read the first 42 bytes of the header    $v_binary_data = fread($this->zip_fd, 42);     // ----- Look for invalid block size    if (strlen($v_binary_data) != 42)    {      $p_header['filename'] = "";      $p_header['status'] = "invalid_header";       // ----- Error log      PclZip::privErrorLog(PCLZIP_ERR_BAD_FORMAT, "Invalid block size : ".strlen($v_binary_data));       // ----- Return      return PclZip::errorCode();    }     // ----- Extract the values    $p_header = unpack('vversion/vversion_extracted/vflag/vcompression/vmtime/vmdate/Vcrc/Vcompressed_size/Vsize/vfilename_len/vextra_len/vcomment_len/vdisk/vinternal/Vexternal/Voffset', $v_binary_data);     // ----- Get filename    if ($p_header['filename_len'] != 0)      $p_header['filename'] = fread($this->zip_fd, $p_header['filename_len']);    else      $p_header['filename'] = '';     // ----- Get extra    if ($p_header['extra_len'] != 0)      $p_header['extra'] = fread($this->zip_fd, $p_header['extra_len']);    else      $p_header['extra'] = '';     // ----- Get comment    if ($p_header['comment_len'] != 0)      $p_header['comment'] = fread($this->zip_fd, $p_header['comment_len']);    else      $p_header['comment'] = '';     // ----- Extract properties     // ----- Recuperate date in UNIX format    //if ($p_header['mdate'] && $p_header['mtime'])    // TBC : bug : this was ignoring time with 0/0/0    if (1)    {      // ----- Extract time      $v_hour = ($p_header['mtime'] & 0xF800) >> 11;      $v_minute = ($p_header['mtime'] & 0x07E0) >> 5;      $v_seconde = ($p_header['mtime'] & 0x001F)*2;       // ----- Extract date      $v_year = (($p_header['mdate'] & 0xFE00) >> 9) + 1980;      $v_month = ($p_header['mdate'] & 0x01E0) >> 5;      $v_day = $p_header['mdate'] & 0x001F;       // ----- Get UNIX date format      $p_header['mtime'] = @mktime($v_hour, $v_minute, $v_seconde, $v_month, $v_day, $v_year);     }    else    {      $p_header['mtime'] = time();

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.