php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #69057 fread() should return bytes read count
Submitted: 2015-02-15 15:15 UTC Modified: 2015-03-01 04:22 UTC
Votes:2
Avg. Score:4.5 ± 0.5
Reproduced:2 of 2 (100.0%)
Same Version:1 (50.0%)
Same OS:1 (50.0%)
From: grzegorz129 at gmail dot com Assigned:
Status: No Feedback Package: Filesystem function related
PHP Version: 5.6.5 OS: All
Private report: No CVE-ID: None
Have you experienced this issue?
Rate the importance of this bug to you:

 [2015-02-15 15:15 UTC] grzegorz129 at gmail dot com
Description:
------------
PHP fread() should provide the same amount of informations as C fread().
fread() in C besides actual data also provides number of bytes read. PHP also implemented similar behaviour but only for fwrite() function.
Changing returned value is of course not an option, but adding optional third parameter is. 



Expected result:
----------------
Declaration of PHP fread() can be changed to:
string fread ( resource $handle , int $length [, int &$size ] )

Actual result:
--------------
Current declaration of fread() doesn't contain read bytes parameter.
string fread ( resource $handle , int $length )

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2015-02-15 19:27 UTC] ab@php.net
-Status: Open +Status: Feedback
 [2015-02-15 19:27 UTC] ab@php.net
strlen(fread(....)) ?

Thanks.
 [2015-02-15 19:46 UTC] grzegorz129 at gmail dot com
Using strlen() adds additional overhead. Using it in fast running loops have significant impact on performance, since function call is rather expensive operation (I'm talking about ~10Gb/s with 128KB chunks).
I see no point of not providing already available information. Unfortunately my PHP source knowledge isn't good enough to reliable propose path.
 [2015-02-15 20:07 UTC] ab@php.net
From that perspective, yes. But please post some PHP code to illustrate this. Do you need this to show something like process progress? Just not sure one would really need this. Normally, even with the big amount of data, it's enough to check the whole size at the end.

Thanks.
 [2015-02-15 20:58 UTC] grzegorz129 at gmail dot com
Unfortunately I cannot show you few lines of example. Due to high throughput my application uses a lot of performance optimisation tricks, one of them is to hold input buffer length as separate variable - it's used later to decide whatever to use substr() or just assign empty string to inputBuffer (believe or not but this simple trick bought me extra 5% of throughput). Besides that length is used in many other places on buffer operations, logging & automatic load balancing are only two real world examples. 
Length is also used to determine disconnection - since length is already in place I check whatever fread() returned 0 bytes instead of making another function call to feof().

Thanks for your support.


p.s. I know I sound crazy, some told me using PHP for high performance TCP server isn't gonna work - I prove them wrong.
 [2015-03-01 04:22 UTC] php-bugs at lists dot php dot net
No feedback was provided. The bug is being suspended because
we assume that you are no longer experiencing the problem.
If this is not the case and you are able to provide the
information that was requested earlier, please do so and
change the status of the bug back to "Re-Opened". Thank you.
 
PHP Copyright © 2001-2019 The PHP Group
All rights reserved.
Last updated: Tue Nov 19 21:01:35 2019 UTC