stream_get_line

(PHP 5)

stream_get_line — Gets line from stream resource up to a given delimiter

Description

string stream_get_line ( resource $handle , int $length [, string $ending ] )

Returns a string of up to length bytes read from the file pointed to by handle . Reading ends when length bytes have been read, when the string specified by ending is found (which is not included in the return value), or on EOF (whichever comes first).

If an error occurs, returns FALSE.

This function is nearly identical to fgets() except in that it allows end of line delimiters other than the standard \n, \r, and \r\n, and does not return the delimiter itself.

See also fread(), fgets(), and fgetc().

Коментарии

Автор:
fgets is faster but stream_get_line is more useful in a tcp server scripts.

when fgets reads some bytes from socket, where EOF is reached, it returns bool(false) same as stream_get_line

BUT if remote client drops connection, and server script will try to read some data with function fgets, function will return bool(false), and stream_get_line will return string(0) ""

so you can detect remote client disconnection with stream_get_line, and cannot with fgets
2009-11-30 11:30:35
http://php5.kiev.ua/manual/ru/function.stream-get-line.html

    Поддержать сайт на родительском проекте КГБ