getid3_handler::fread( int $bytes ): string|false
- Source
wp-includes/ID3/getid3.php:2236
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
$bytesint
Return value
string|false
Performance profile
How much work a call to getid3_handler::fread() 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
- 6–39
- Plugin surface
- None
- Called by
- 1
Reads or writes the filesystem via fread().
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 85.
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
fread()called directly
What one call costs · 4 distinct outcomes
One number would be a lie: the work depends on which branch runs. These are every distinct cost getid3_handler::fread() can have, taken from its control-flow graph on PHP 8.5.
| When | Instructions | Calls it makes |
|---|---|---|
| always | 6–11 | none |
$bytes != 0 && $bytes | 18 | ->ftell() |
$bytes != 0 && !$bytes | 25–39 | ->ftell(), ::getid3_lib(), ->ftell() |
$bytes != 0 && !$bytes && ::getid3_lib() | 32–39 | ->ftell(), ::getid3_lib(), fread() |
Across PHP versions
| PHP | Compiled | Executed | Branches | Notes |
|---|---|---|---|---|
| 8.6-dev | 85 | 6–39 | 8 | |
| 8.5 | 85 | 6–39 | 8 | |
| 8.4 | 85 | 6–39 | 8 | 3 fewer instructions than PHP 8.3 |
| 8.3 | 88 | 6–39 | 8 | |
| 8.2 | 88 | 6–39 | 8 | |
| 8.1 | 88 | 6–39 | 8 | |
| 7.4 | 88 | 6–39 | 8 |
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_exception::__construct()
- getid3_handler::ftell()
- getid3_lib::intValueSupported()
Used by · 1
Source code
protected function fread($bytes) { if ($this->data_string_flag) { $this->data_string_position += $bytes; return substr($this->data_string, $this->data_string_position - $bytes, $bytes); } if ($bytes == 0) { return ''; } elseif ($bytes < 0) { throw new getid3_exception('cannot fread('.$bytes.' from '.$this->ftell().')', 10); } $pos = $this->ftell() + $bytes; if (!getid3_lib::intValueSupported($pos)) { throw new getid3_exception('cannot fread('.$bytes.' from '.$this->ftell().') because beyond PHP filesystem limit', 10); } //return fread($this->getid3->fp, $bytes); /* * https://www.getid3.org/phpBB3/viewtopic.php?t=1930 * "I found out that the root cause for the problem was how getID3 uses the PHP system function fread(). * It seems to assume that fread() would always return as many bytes as were requested. * However, according the PHP manual (http://php.net/manual/en/function.fread.php), this is the case only with regular local files, but not e.g. with Linux pipes. * The call may return only part of the requested data and a new call is needed to get more." */ $contents = ''; do { //if (($this->getid3->memory_limit > 0) && ($bytes > $this->getid3->memory_limit)) { if (($this->getid3->memory_limit > 0) && (($bytes / $this->getid3->memory_limit) > 0.99)) { // enable a more-fuzzy match to prevent close misses generating errors like "PHP Fatal error: Allowed memory size of 33554432 bytes exhausted (tried to allocate 33554464 bytes)" throw new getid3_exception('cannot fread('.$bytes.' from '.$this->ftell().') that is more than available PHP memory ('.$this->getid3->memory_limit.')', 10); } $part = fread($this->getid3->fp, $bytes); $partLength = strlen($part); $bytes -= $partLength; $contents .= $part; } while (($bytes > 0) && ($partLength > 0)); return $contents; }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.