It is a GOOD_THING to check the return value from fclose(), as some operating systems only flush file output on close, and can, therefore, return an error from fclose(). You can catch severe data-eating errors by doing this.
I learned this the hard way.
PHP.mk документација
fclose
Почист и полокален преглед на PHP референцата, со задржана структура од PHP.net и подобра читливост за примери, секции и белешки.
Патека
function.fclose.php
Локална патека за оваа страница.
Извор
php.net/manual/en
Оригиналниот HTML се реупотребува и локално се стилизира.
Режим
Прокси + превод во позадина
Кодовите, табелите и белешките остануваат читливи во истиот тек.
Референца
function.fclose.php
fclose
Референца за `function.fclose.php` со подобрена типографија и навигација.
fclose
(PHP 4, PHP 5, PHP 7, PHP 8)
fclose — Го затвора отворениот покажувач на датотека
Параметри
stream-
Показалецот на датотеката мора да биде валиден и мора да покажува на датотека успешно отворена од fopen() or fsockopen().
Вратени вредности
Патеката до PHP скриптата што треба да се провери. true на успех или false при неуспех.
Примери
Пример #1 Едноставен fclose() example
<?php
$handle = fopen('somefile.txt', 'r');
fclose($handle);
?>Белешки од корисници 6 белешки
jricher на jacquesricher dot com ¶
21 години пред
Glenn S ¶
3 години пред
Note that from PHP 8.0 onwards, attempting to close a stream that is already closed will throw a fatal TypeError.
Prior to PHP 8, this just caused a warning (that you can silence with @).
jgotti ¶
пред 13 години
In case you have some trouble to properly disconnect some client streams opened with stream_socket_server / stream_select you should give a try to stream_socket_shutdown.
<?php stream_socket_shutdown($clientStream,STREAM_SHUT_RDWR); ?>
daniel7 dot martinez на ps dot ge dot com ¶
figroc at gmail dot com
Generally, it's always a good idea to close a file when you're done with it. It's very easy for something to go wrong and corrupt a file that hasn't been closed properly. If you're concerned about efficiency, the overhead is negligible.
mark на markvange * com ¶
19 години пред
It is very important to make sure you clear any incoming packets out of the incoming buffer using fread() or some equivalent. Although you can call fclose() the socket does not actually shut down until the inbound packets have been cleared. This can lead to some confusion.
tom dot vom dot berg на online dot de ¶
пред 11 години
if you want to daysychain a filehandle through some functions and each function is allowed to close th file you might look in a following function first, if the handle is still valid.
Opening a file, there often will be used a code like
if (!$fh = fopen($filename, $mode)) return false;
But if you possably have closed the file and you want to check that, a smililar statement would not work.
DOES NOT WORK: if (!$fh) end_of_chain();
use beter: if (is_resource($fh)) end_of_chain();