stream_get_line
(PHP 5)
stream_get_line — Gets line from stream resource up to a given delimiter
Description
$handle
, int $length
[, string $ending
] )Gets a line from the given 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).
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.
Parameters
-
handle
-
A valid file handle.
-
length
-
The number of bytes to read from the handle.
-
ending
-
An optional string delimiter.
Return Values
Returns a string of up to length
bytes read from the file
pointed to by handle
.
If an error occurs, returns FALSE
.
- PHP Руководство
- Функции по категориям
- Индекс функций
- Справочник функций
- Другие базовые расширения
- Потоки
- set_socket_blocking
- stream_bucket_append
- stream_bucket_make_writeable
- stream_bucket_new
- stream_bucket_prepend
- stream_context_create
- stream_context_get_default
- stream_context_get_options
- stream_context_get_params
- stream_context_set_default
- stream_context_set_option
- stream_context_set_params
- stream_copy_to_stream
- stream_encoding
- stream_filter_append
- stream_filter_prepend
- stream_filter_register
- stream_filter_remove
- stream_get_contents
- stream_get_filters
- stream_get_line
- stream_get_meta_data
- stream_get_transports
- stream_get_wrappers
- stream_is_local
- stream_notification_callback
- stream_register_wrapper
- stream_resolve_include_path
- stream_select
- stream_set_blocking
- stream_set_chunk_size
- stream_set_read_buffer
- stream_set_timeout
- stream_set_write_buffer
- stream_socket_accept
- stream_socket_client
- stream_socket_enable_crypto
- stream_socket_get_name
- stream_socket_pair
- stream_socket_recvfrom
- stream_socket_sendto
- stream_socket_server
- stream_socket_shutdown
- stream_supports_lock
- stream_wrapper_register
- stream_wrapper_restore
- stream_wrapper_unregister
Коментарии
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