Req #69057 [Fbk->NoF]: fread() should return bytes read count
| From: | php-bugs at lists dot php dot net | Date: | Sun, 01 Mar 2015 04:22:19 +0000 |
| Subject: | Req #69057 [Fbk->NoF]: fread() should return bytes read count | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-191017@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=69057&edit=1
ID: 69057
Updated by: php-bugs@lists.php.net
Reported by: grzegorz129 at gmail dot com
Summary: fread() should return bytes read count
-Status: Feedback
+Status: No Feedback
Type: Feature/Change Request
Package: Filesystem function related
Operating System: All
PHP Version: 5.6.5
Private report: N
New Comment:
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.
Previous Comments:
------------------------------------------------------------------------
[2015-02-15 20:58:43] 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-02-15 20:07:40] 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 19:46:17] 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 19:27:22] ab@php.net
strlen(fread(....)) ?
Thanks.
------------------------------------------------------------------------
[2015-02-15 15:15:37] 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 )
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=69057&edit=1