hi
Is there a posibility in PHP
- to read a file as stream
- or to specefy a timeout for reading files as it is with streams
- or a way to find out wether a file has data in it without EOF
i try to read from /dev/random wich is no problem as long as it is not empty.
But if it is empty it does not return a EOF but hangs the script till there is more data.
filesize() always returns 0.
here is a little funktion showing what i try to do (off cause it doesn’t work as there is no timeout for files):
[php]
function getrand($length=1)
{
$rand=array();
if($devrandom=fopen(’/dev/random’,‘rb’))
{
stream_set_timeout($devrandom,1);
do
{
$rand[]=ord(fgetc($devrandom));
$info = stream_get_meta_data($fp);
}
while(count($rand)<$length and isset($info[‘timed_out’]) and !$info[‘timed_out’]);
fclose($fp);
}
echo implode(’,’,$rand);
mt_srand();
while(count($rand)<$length)
{
$rand[]=mt_rand(0,255);
}
return $rand;
}
[/php]
i try to get this to work for hours.
i’m thankfull for any ideas.
Q