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
- Scaling
- Constant
- Instructions
- 8–92
- Plugin surface
- None
- Called by
- 1
Reads or writes the filesystem via file_exists().
No loop in the body: the same number of instructions runs whatever you pass in.
Executed per call on PHP 8.5, depending on the branch taken. The body compiles to 210.
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
file_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.
| When | Instructions | Calls it makes |
|---|---|---|
| always | 8–13 | ->error() |
empty($value) | 14–39 | none |
empty($value) | 23–46 | md5_file() |
empty($value) | 23–48 | sha1_file() |
| always | 29–53 | ::getid3_lib() |
!empty($value) | 33–36 | ini_get(), ->warning() |
!empty($value) && !file_exists() && empty($VorbisCommentError) | 67–75 | ini_get(), ignore_user_abort(), tempnam(), touch(), tempnam(), file_exists(), unlink(), unlink(), ignore_user_abort() |
!empty($value) && !file_exists() && empty($VorbisCommentError) | 74–81 | ini_get(), ignore_user_abort(), tempnam(), touch(), tempnam(), file_exists(), sha1_file(), unlink(), unlink(), ignore_user_abort() |
!empty($value) && !file_exists() && empty($VorbisCommentError) | 75–80 | ini_get(), ignore_user_abort(), tempnam(), touch(), tempnam(), file_exists(), md5_file(), unlink(), unlink(), ignore_user_abort() |
!empty($value) && !file_exists() && !empty($VorbisCommentError) | 77–80 | ini_get(), ignore_user_abort(), tempnam(), touch(), tempnam(), file_exists(), ->warning(), unlink(), unlink(), ignore_user_abort() |
!empty($value) && empty($VorbisCommentError) | 77–85 | ini_get(), ignore_user_abort(), tempnam(), touch(), tempnam(), escapeshellarg(), escapeshellarg(), escapeshellarg(), shell_exec(), unlink(), unlink(), ignore_user_abort() |
!empty($value) && file_exists() && empty($VorbisCommentError) | 78–86 | ini_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–91 | ini_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–92 | ini_get(), ignore_user_abort(), tempnam(), touch(), tempnam(), file_exists(), shell_exec(), sha1_file(), unlink(), unlink(), ignore_user_abort() |
!empty($value) && empty($VorbisCommentError) | 85–90 | ini_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–91 | ini_get(), ignore_user_abort(), tempnam(), touch(), tempnam(), file_exists(), shell_exec(), md5_file(), unlink(), unlink(), ignore_user_abort() |
!empty($value) && !empty($VorbisCommentError) | 87–90 | ini_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–91 | ini_get(), ignore_user_abort(), tempnam(), touch(), tempnam(), file_exists(), shell_exec(), ->warning(), unlink(), unlink(), ignore_user_abort() |
Across PHP versions
| PHP | Compiled | Executed | Branches | Notes |
|---|---|---|---|---|
| 8.6-dev | 210 | 8–92 | 20 | |
| 8.5 | 210 | 8–92 | 20 | |
| 8.4 | 210 | 8–92 | 20 | 3 fewer instructions than PHP 8.3 |
| 8.3 | 213 | 8–95 | 20 | |
| 8.2 | 213 | 8–95 | 20 | 2 more instructions than PHP 8.1 |
| 8.1 | 211 | 8–97 | 20 | 4 more instructions than PHP 7.4 |
| 7.4 | 207 | 8–94 | 20 |
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
- getID3::error()Error handling.
- getID3::warning()Warning handling.
- getid3_lib::hash_data()Returns checksum for a file from starting position to absolute end position.
Used by · 1
- getID3::analyze()analyze file
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.
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.