fclose

(PHP 4, PHP 5)

fclose — Закрывает дескриптор файла

Описание

bool fclose ( resource $handle )

Функция закрывает файл, на который указывает handle .

Возвращает TRUE в случае успешного завершения или FALSE в случае возникновения ошибки.

Дескриптор должен указывать на файл, открытый ранее с помощью функции fopen() или fsockopen().

Пример #1 Простой пример использования функции fclose()

<?php

  $handle 
fopen('somefile.txt''r');
  
  
fclose($handle);
  
?>

Коментарии

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.
2001-09-10 19:06:19
http://php5.kiev.ua/manual/ru/function.fclose.html
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.
2005-02-01 08:06:30
http://php5.kiev.ua/manual/ru/function.fclose.html
Автор:
In response to kumar mcmillan 'gotcha' note below, we get a different result on a W2K machine:

<?php
$file_pointer 
fopen('textfile.dat''r');
fclose($file_pointer);
echo 
'$file_pointer is resource = ' . (is_resource($file_pointer) ? 'true''false');
?>

output:
$file_pointer is resource = false
2005-11-28 11:02:34
http://php5.kiev.ua/manual/ru/function.fclose.html
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.
2006-05-05 00:17:56
http://php5.kiev.ua/manual/ru/function.fclose.html
Автор:
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); ?>
2012-09-07 21:25:41
http://php5.kiev.ua/manual/ru/function.fclose.html
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();
2014-04-28 23:38:11
http://php5.kiev.ua/manual/ru/function.fclose.html
Автор:
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 @).
2023-02-07 02:30:19
http://php5.kiev.ua/manual/ru/function.fclose.html

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