I would use exec()
to run a local hashing function in the shell and return the value back to the php script. Here's an example with md5
but any algo available can be used.
$results = array();
$filename = '/full/path/to/file';
exec("md5sum $filename", $results);
Then parse the result array (the output of the shell command).
In general, I like to avoid doing anything directly in PHP that requires more than 1G of memory, especially if running in php-fpm or as an apache module--sort of time reinforced prejudice. This is definitely my advice when there is a native application that can accomplish the goal and you don't particularly need portablitly cross platform (like run on both linux and windows machines).