hash_update_stream()

hash_update_stream() — Pump data into an active hashing context from an open stream.

Built-in function of PHP 8.5. The manual lists it as available in PHP 5 >= 5.1.2, PHP 7, PHP 8, PECL hash >= 1.1. This page is the reference card: signature, parameters and return value, plus the changelog and the example the manual provides.

Signature

hash_update_stream(HashContext $context, resource $stream, int $length = -1): int

Parameters

ParameterTypeWhat it takes
$contextHashContextHashing context returned by hash_init().
$streamresourceOpen file handle as returned by any stream creation function.
$lengthintMaximum number of characters to copy from stream into the hashing context.

Return value

Actual number of bytes added to the hashing context from stream.

Example

A runnable snippet:

$fp = tmpfile(); fwrite($fp, 'jumped over the lazy dog.'); rewind($fp); $ctx = hash_init('sha256'); hash_update($ctx, 'The quick brown fox '); hash_update_stream($ctx, $fp); echo hash_final($ctx);

Output:

68b1282b91de2c054c36629cb8dd447f12f096d3e3c587978dc2248444633483

Changelog

VersionChange
7.2.0Accept HashContext instead of resource.

See also

hash_init(), hash_update(), hash_final()

All PHP 8.5 built-in functions

Reference card built from the PHP manual page hash_update_stream() (PHP documentation, CC BY 3.0). The page is generated from the manual, so the wording of the parameter and return value text follows php.net.