performance - Overhead of large length in PHP stream_get_line() -


i'm testing out php library relies upon streams based library. experience sockets low level compared streams i'm little unsure if streams going flexible enough.

basically, using sockets, write buffer loop checked each chunk of data eol character \n so...

php

$data = null; while ($buffer = socket_read($connection,1024)) {     $data .= $buffer;     if (strpos($buffer, "\n") !== false) {         $data = substr($data,0,-1);         break;     } } 

i'm looking similar without having rewrite entire library. here's problem...

stream_get_line($handle,$length,$eol) accepts length value truncate longer that. php docs state...

reading ends when length bytes have been read, when string specified ending found (which not included in return value), or on eof (whichever comes first).

... , there's no offset param can't use same way remainder. means if don't know length of data, or if it's inconsistent, need set length high enough deal possible length of data.

that isn't big concern, seems work. question will setting $length value 512000 (500kb) cause lot of unnecessary overhead shorter responses?

as far statement docs:

reading ends when length bytes have been read, when string specified ending found (which not included in return value), or on eof (whichever comes first).

this doesn't mean if pass length of 1,024 or 200,000 , line longer rest of data truncated or lost. maximum amount of data call return if doesn't reach eof/eol before that.

so if have line 102,500 bytes long , have length parameter set 1024, have have called stream_get_line 101 times before entire line of data read but entire line read, not in 1 call function.

to directly answer question, there won't overhead short responses if pass large value. how works under hood depends on type of stream reading from. in case of network stream large length value, may take long time before call returns data in event takes long time length data read network, if reading in smaller chunks, might start more data network before has been received.


Comments

Popular posts from this blog

android - MPAndroidChart - How to add Annotations or images to the chart -

javascript - Add class to another page attribute using URL id - Jquery -

firefox - Where is 'webgl.osmesalib' parameter? -