note 42715 added to function.ftok
| From: | david dot rech at virusmedia dot de | Date: | Wed, 26 May 2004 23:50:47 +0000 |
| Subject: | note 42715 added to function.ftok | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-70155@lists.php.net to get a copy of this message | ||
Missing ftok() on Windows? Here's my little workaround:
<?php
if( !function_exists('ftok') )
{
function ftok($filename = "", $proj = "")
{
if( empty($filename) || !file_exists($filename) )
{
return -1;
}
else
{
$filename = $filename . (string) $proj;
for($key = array(); sizeof($key) < strlen($filename); $key[] = ord(substr($filename,
sizeof($key), 1)));
return dechex(array_sum($key));
}
}
}?>
NOTE: There *may* be duplicate keys, even if probability is low.
The key's were NOT computed like the original UNIX ftok() because i.e. fileinode() is also
missing on windows. Normally ftok() computes a key based on the file inode and the system minor id
of the harddrive the file resides.
Behaviour is like PHPs ftok(), -1 is returned if file is missing or $filename is empty, computed int
as hex on success.
--
Regards,
David Rech
----
Manual Page -- http://www.php.net/manual/en/function.ftok.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+42715
Delete -- http://master.php.net/manage/user-notes.php?action=delete+42715&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+42715&report=yes
Search -- http://master.php.net/manage/user-notes.php