Re: Idea for a new extensions: checksum_from_file()
| From: | Johannes Schlüter | Date: | Sun, 24 Jun 2007 14:43:54 +0000 |
| Subject: | Re: Idea for a new extensions: checksum_from_file() | ||
| References: | 1 2 3 | Groups: | php.pecl.dev |
| Request: | Send a blank email to pecl-dev+get-4741@lists.php.net to get a copy of this message | ||
Hi,
if the functions I mentioned in the last mail - especially in
combination with a stream_wrapper/stream_filter, which might give you
the offsets - aren't enough for your needs feel free to propose a
patch.
johannes
On Sun, 2007-06-24 at 04:25 -0700, ecc wrote:
> Ah, never seen hash extension. But there is no function, handeling offsets
> internaly.
>
> hash_update could use offsets... but this isnt performant. Why handeling
> this filedata within the php script? Thats the way, i allready handel this
> without "hash".
>
> Can you give me an example to made this command performant with the hash
> functions for an 600 MB file?
>
> In my example/idea, you dont have to read all into an variable to create the
> checksum, only the php_extension do this transparent. Maybe its an idea to
> add such a feature to the hash-extension.
>
> // My idea:
> // all filedata is handeled transparent, only the checksums are returned.
> checksum_from_file($file, array('crc32', 'md5'), 512, -128, array($this,
> 'updateProcess', 1024));
>
> I dont need the raw filedata in my script... i only need the checksum. I
> think, done in c this is mutch faster, isnt it?
>
> With "hash_update" you have read the whole file using
>
> while (!feof($fp)) {
> $buffer = fgets($fp, 65536);
> hash_update($ctx, $buffer);
> }
>
> Not really performant, isnt it?
>
> Regards,
> Andreas
>
>
> Johannes Schlueter wrote:
> >
> > Hi Andreas,
> >
> > since PHP 5.2.1 PHP bundles the hash extension, see php.net/hash which
> > includes way more hashing algorithms (see hash_algos()) and a
> > hash_file() function and should full-fill all your needs.
> >
> > johannes
> >
> > On Sun, 2007-06-24 at 02:16 -0700, ecc wrote:
> >> Hi,
> >>
> >> there are 3 checksums supported in php. (md5, crc32 and sha1, Mabye there
> >> are more...)
> >>
> >> md5 and sha1 allready have an *_file function available, crc32 dont have
> >> them. crc32 dont have this function in the latest php version.
> >>
> >> These *_file functions are usefull in the most cases, but have a very big
> >> disadvantage. They could not handle header offsets.
> >>
> >> Theses header offsets arent trivial, because e.g. MP3 files also contains
> >> an
> >> header. (In this case, its not really an header, because its an offset at
> >> the end of the MP3 file containing the meta-informations ID3). So if you
> >> parse the checksum of an MP3, you allway get the wrong checksum, because
> >> the
> >> song is the same in the most cases, but only the meta-infos are changed.
> >> This isnt the best example, but it shows you the problem.
> >>
> >> This is my implementation idea (pseudocode).
> >>
> >> // get crc32 and md5 checksums from $file, begin at byte 512 and stop 128
> >> bytes before fileend.
> >> // call method "updateProcess" everytime if 1024 bytes for file are
> >> processed! (eg. for php-gtk2)
> >> checksum_from_file($file, array('crc32', 'md5'), 512, -128,
> >> array($this,
> >> 'updateProcess', 1024));
> >>
> >> public function checksum_from_file($file= false, $checksum_type = false,
> >> $start_offset=false, $end_offset=false, $callback = false) {
> >> $checksums = array();
> >> // get data
> >> return $checksums;
> >> }
> >>
> >> $file should be contain a filename, a filehandle or and something like
> >> this
> >> z:/test.zip#filename.php
> >> So the creation of temp-copys of e.g. zip content could be transparent
> >> done
> >> without managing this externaly.
> >>
> >> This extension have to parse files bigger than 600 MB. So, the funktion
> >> have
> >> to be ready for this. (file_get_contents crash in this cases :-))
> >>
> >> Now, i have to read the complete filecontent to the memory using a php
> >> buildin function and create an checksum by this string, because i´ve had
> >> to
> >> manage the header offsets. Not really performant, and very very slow for
> >> large files > 64 MB
> >>
> >> Regards,
> >> Andreas
> >> http://www.php-gtk.eu/apps/emucontrolcenter
> >>
> >> Here an overview of the allready implemented checksum function in php.
> >>
> >> string md5_file ( string $filename [, bool $raw_output] )
> >> http://de2.php.net/manual/de/function.md5-file.php
> >>
> >> string sha1_file ( string $filename [, bool $raw_output] )
> >> http://de2.php.net/manual/de/function.sha1-file.php
> >>
> >> int crc32 ( string $str )
> >> http://de2.php.net/manual/de/function.crc32.php
> >
> > --
> > PECL development discussion Mailing List (http://pecl.php.net/)
> > To unsubscribe, visit: http://www.php.net/unsub.php
> >
> >
> >
>
> --
> View this message in context:
> http://www.nabble.com/Idea-for-a-new-extensions%3A-checksum_from_file%28%29-tf3971680.html#a11274130¤$ñßz†>¯‰ØÛ‹ƒã
>
> Sent from the Pecl - Dev mailing list archive at Nabble.com.