The PHP Function fflush
The function fflush (or fclose in some cases) is often used in web applications to ensure that the file changes made by PHP are actually written to disk. The problem is that writing to a file does not actually guarantee that the data will be flushed to disk - it might still end up in your PHP process buffer instead, and if something happens (like a power outage) before the write completes then your changes might not be written at all.
Fortunately, fflush is a very simple function that works as it should; the only requirement is that you call it after any fwrite operation. This ensures that any data that is in your PHP process buffer is actually written to the file, and that the st_ctime and st_mtime fields of the underlying operating system are updated as well.
PHP 8.1 introduces several new features that improve the core and the library, but more than ten existing functions have been deprecated. Here’s a quick rundown of the most important ones:
Float coercion is an essential part of PHP programming, but sometimes it can be confusing. In this article, we’ll show you how to use float coercion safely while avoiding some common mistakes.