php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #6068 fread stops
Submitted: 2000-08-10 06:17 UTC Modified: 2000-09-03 18:06 UTC
From: richard at zend dot com Assigned:
Status: Closed Package: Misbehaving function
PHP Version: 4.0.1pl2 OS: Win98
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: richard at zend dot com
New email:
PHP Version: OS:

 

 [2000-08-10 06:17 UTC] richard at zend dot com
<HTML><BODY>
<?php
	set_time_limit(0);
	clearstatcache();
	$input = fopen('C:/phpcvs/phpcvs.tar.gz', 'r') or die('could not open input');
	$output = fopen('A:/phpcvs.tar.gz.1', 'w') or die('could not open ouput');
	$start = 0;
	$chunk = 100;
	$length = 1024*1024;
	fseek($input, $start);
	$current = $start;
	echo "Filesize is ", filesize('C:/phpcvs/phpcvs.tar.gz'), "<BR>\n";
	while ($current < $length && !feof($input)){
		$data = fread($input, $chunk);
		$wrote = fwrite($output, $data, $chunk);
		$current += $wrote;
		echo $current, "<BR>\n";
		flush();
	}
	$count = 330;
	(fseek($input, 330)+1) or die ("Error fseeking 330<BR>\n");
	while (!feof($input) && $count < 350){
		$char = fgetc($input);
		echo ftell($input), " '$char' (", ord($char), ")<BR>\n";
		$count++;
	}
	fclose($input);
	fclose($output);
	echo "<BR>Done.";
?>
</BODY></HTML>

OUTPUT:
Filesize is 2233724
100
200
300
337
331 '' (0)
332 'S' (83)
333 ';' (59)
334 'N' (78)
335 ';' (59)
336 '?' (245)
337 '|' (124)
338 '?' (137)
842 '?' (200)
4427 '' (16)
4428 'x' (120)
4429 'F' (70)
4430 '^' (94)
4431 'e' (101)
4432 '?' (154)
4433 '?' (235)
4434 '?' (239)
4435 '' (15)
4436 '7' (55)
4437 'b' (98)

Done.

Expected Output:
1.4 Megs copied 100 bytes at a time, and something sensible from ftell after byte 338...
filesize() knows how big the file is, but fread, feof, fgetc, etc are all convinced it's only 337 bytes long...
But char 337 and 338 are not even end of string.  331 is, but it's not even dying there, which would almost make sense, except fread and fgetc are supposed to be binary safe...

The mod_php4.dll from that geocities guy is in there...  Relevant?  One wouldn't think so...
The php.exe seems to work just fine, so I guess it is though, unless it's in some other DLL that gets involved with Apache and PHP somehow, but not with PHP.exe.

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2000-09-02 22:31 UTC] sniper@php.net
Is this still happening with newer version? (Like php4.0.2 ?)

--Jani
 [2000-09-03 18:06 UTC] sniper@php.net
Feedback:
"Seems to work okay...  But I don't have the exact same file to test on. :-("

Please reopen if this problem resurfaces later.

--Jani
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Wed May 01 23:01:28 2024 UTC