wppaste
WordPress

getID3::getHashdata( string $algorithm ): array|bool

Source
wp-includes/ID3/getid3.php:1771

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

$algorithmstring

Return value

array|bool

Performance profile

How much work a call to getID3::getHashdata() 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 file_exists().

Scaling
Constant

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

Instructions
8–92

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

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 accessfile_exists()called directly

What one call costs · 18 distinct outcomes

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

WhenInstructionsCalls it makes
always8–13->error()
empty($value)14–39none
empty($value)23–46md5_file()
empty($value)23–48sha1_file()
always29–53::getid3_lib()
!empty($value)33–36ini_get(), ->warning()
!empty($value) && !file_exists() && empty($VorbisCommentError)67–75ini_get(), ignore_user_abort(), tempnam(), touch(), tempnam(), file_exists(), unlink(), unlink(), ignore_user_abort()
!empty($value) && !file_exists() && empty($VorbisCommentError)74–81ini_get(), ignore_user_abort(), tempnam(), touch(), tempnam(), file_exists(), sha1_file(), unlink(), unlink(), ignore_user_abort()
!empty($value) && !file_exists() && empty($VorbisCommentError)75–80ini_get(), ignore_user_abort(), tempnam(), touch(), tempnam(), file_exists(), md5_file(), unlink(), unlink(), ignore_user_abort()
!empty($value) && !file_exists() && !empty($VorbisCommentError)77–80ini_get(), ignore_user_abort(), tempnam(), touch(), tempnam(), file_exists(), ->warning(), unlink(), unlink(), ignore_user_abort()
!empty($value) && empty($VorbisCommentError)77–85ini_get(), ignore_user_abort(), tempnam(), touch(), tempnam(), escapeshellarg(), escapeshellarg(), escapeshellarg(), shell_exec(), unlink(), unlink(), ignore_user_abort()
!empty($value) && file_exists() && empty($VorbisCommentError)78–86ini_get(), ignore_user_abort(), tempnam(), touch(), tempnam(), file_exists(), shell_exec(), unlink(), unlink(), ignore_user_abort()
6 further outcomes, up to 91 instructions
!empty($value) && empty($VorbisCommentError)84–91ini_get(), ignore_user_abort(), tempnam(), touch(), tempnam(), escapeshellarg(), escapeshellarg(), escapeshellarg(), shell_exec(), sha1_file(), unlink(), unlink(), ignore_user_abort()
!empty($value) && file_exists() && empty($VorbisCommentError)85–92ini_get(), ignore_user_abort(), tempnam(), touch(), tempnam(), file_exists(), shell_exec(), sha1_file(), unlink(), unlink(), ignore_user_abort()
!empty($value) && empty($VorbisCommentError)85–90ini_get(), ignore_user_abort(), tempnam(), touch(), tempnam(), escapeshellarg(), escapeshellarg(), escapeshellarg(), shell_exec(), md5_file(), unlink(), unlink(), ignore_user_abort()
!empty($value) && file_exists() && empty($VorbisCommentError)86–91ini_get(), ignore_user_abort(), tempnam(), touch(), tempnam(), file_exists(), shell_exec(), md5_file(), unlink(), unlink(), ignore_user_abort()
!empty($value) && !empty($VorbisCommentError)87–90ini_get(), ignore_user_abort(), tempnam(), touch(), tempnam(), escapeshellarg(), escapeshellarg(), escapeshellarg(), shell_exec(), ->warning(), unlink(), unlink(), ignore_user_abort()
!empty($value) && file_exists() && !empty($VorbisCommentError)88–91ini_get(), ignore_user_abort(), tempnam(), touch(), tempnam(), file_exists(), shell_exec(), ->warning(), unlink(), unlink(), ignore_user_abort()

Across PHP versions

PHPCompiledExecutedBranchesNotes
8.6-dev2108–9220
8.52108–9220
8.42108–92203 fewer instructions than PHP 8.3
8.32138–9520
8.22138–95202 more instructions than PHP 8.1
8.12118–97204 more instructions than PHP 7.4
7.42078–9420

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

Used by · 1

Source code

	public function getHashdata($algorithm) {		switch ($algorithm) {			case 'md5':			case 'sha1':				break; 			default:				return $this->error('bad algorithm "'.$algorithm.'" in getHashdata()');		} 		if (!empty($this->info['fileformat']) && !empty($this->info['dataformat']) && ($this->info['fileformat'] == 'ogg') && ($this->info['audio']['dataformat'] == 'vorbis')) { 			// We cannot get an identical md5_data value for Ogg files where the comments			// span more than 1 Ogg page (compared to the same audio data with smaller			// comments) using the normal getID3() method of MD5'ing the data between the			// end of the comments and the end of the file (minus any trailing tags),			// because the page sequence numbers of the pages that the audio data is on			// do not match. Under normal circumstances, where comments are smaller than			// the nominal 4-8kB page size, then this is not a problem, but if there are			// very large comments, the only way around it is to strip off the comment			// tags with vorbiscomment and MD5 that file.			// This procedure must be applied to ALL Ogg files, not just the ones with			// comments larger than 1 page, because the below method simply MD5's the			// whole file with the comments stripped, not just the portion after the			// comments block (which is the standard getID3() method. 			// The above-mentioned problem of comments spanning multiple pages and changing			// page sequence numbers likely happens for OggSpeex and OggFLAC as well, but			// currently vorbiscomment only works on OggVorbis files. 			if (preg_match('#(1|ON)#i', ini_get('safe_mode'))) { 				$this->warning('Failed making system call to vorbiscomment.exe - '.$algorithm.'_data is incorrect - error returned: PHP running in Safe Mode (backtick operator not available)');				$this->info[$algorithm.'_data'] = false; 			} else { 				// Prevent user from aborting script				$old_abort = ignore_user_abort(true); 				// Create empty file				$empty = tempnam(GETID3_TEMP_DIR, 'getID3');				touch($empty); 				// Use vorbiscomment to make temp file without comments				$temp = tempnam(GETID3_TEMP_DIR, 'getID3');				$file = $this->info['filenamepath']; 				if (GETID3_OS_ISWINDOWS) { 					if (file_exists(GETID3_HELPERAPPSDIR.'vorbiscomment.exe')) { 						$commandline = '"'.GETID3_HELPERAPPSDIR.'vorbiscomment.exe" -w -c "'.$empty.'" "'.$file.'" "'.$temp.'"';						$VorbisCommentError = shell_exec($commandline); 					} else { 						$VorbisCommentError = 'vorbiscomment.exe not found in '.GETID3_HELPERAPPSDIR; 					} 				} else { 					$commandline = 'vorbiscomment -w -c '.escapeshellarg($empty).' '.escapeshellarg($file).' '.escapeshellarg($temp).' 2>&1';					$VorbisCommentError = shell_exec($commandline); 				} 				if (!empty($VorbisCommentError)) { 					$this->warning('Failed making system call to vorbiscomment(.exe) - '.$algorithm.'_data will be incorrect. If vorbiscomment is unavailable, please download from http://www.vorbis.com/download.psp and put in the getID3() directory. Error returned: '.$VorbisCommentError);					$this->info[$algorithm.'_data'] = false; 				} else { 					// Get hash of newly created file					switch ($algorithm) {						case 'md5':							$this->info[$algorithm.'_data'] = md5_file($temp);							break;

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-includes/ID3/getid3.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.