hash_update_stream() – Populate an Active Hash Context from an Open Stream (PHP)
The article explains the PHP function hash_update_stream(), detailing its signature, parameters (context, handle, length), return value, and provides a complete example that reads data from a temporary file stream, updates an MD5 hash context, and outputs the resulting hash.
The PHP function hash_update_stream() reads data from an open stream and feeds it into an active hash context, allowing incremental hashing of large data sources.
Signature:
int hash_update_stream(resource $context, resource $handle[, int $length = -1])Parameters:
context : the hash context resource returned by hash_init().
handle : an open file handle representing the stream to read from.
length (optional): the maximum number of bytes to copy from the handle; default -1 means read until EOF.
Return value: the number of bytes actually read from the handle and added to the hash context.
Example:
<?php
$fp = tmpfile();
fwrite($fp, 'The quick brown fox jumped over the lazy dog.');
rewind($fp);
$ctx = hash_init('md5');
hash_update_stream($ctx, $fp);
echo hash_final($ctx);
?>The script outputs the MD5 hash of the string, for example:
5c6ffbdd40d9556b73a21e63c3e0e904Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
Laravel Tech Community
Specializing in Laravel development, we continuously publish fresh content and grow alongside the elegant, stable Laravel framework.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
