fflush example


  public function stream_seek($offset$whence = SEEK_SET) {
    // fseek returns 0 on success and -1 on a failure.     // stream_seek 1 on success and 0 on a failure.     return !fseek($this->handle, $offset$whence);
  }

  /** * {@inheritdoc} */
  public function stream_flush() {
    return fflush($this->handle);
  }

  /** * {@inheritdoc} */
  public function stream_tell() {
    return ftell($this->handle);
  }

  /** * {@inheritdoc} */
// Attempt to acquire an exclusive lock for writing     $this->assertFalse(@flock($handle, LOCK_EX | LOCK_NB), 'Unable to acquire an exclusive lock using the read-only stream wrapper.');
    // Attempt to obtain a shared lock     $this->assertTrue(flock($handle, LOCK_SH | LOCK_NB), 'Able to acquire a shared lock using the read-only stream wrapper.');
    // Attempt to release a shared lock     $this->assertTrue(flock($handle, LOCK_UN | LOCK_NB), 'Able to release a shared lock using the read-only stream wrapper.');
    // Attempt to truncate the file     $this->assertFalse(@ftruncate($handle, 0), 'Unable to truncate using the read-only stream wrapper.');
    // Attempt to write to the file     $this->assertEquals(0, @fwrite($handle$this->randomMachineName()), 'Unable to write to file using the read-only stream wrapper.');
    // Attempt to flush output to the file     $this->assertFalse(@fflush($handle), 'Unable to flush output to file using the read-only stream wrapper.');
    // Attempt to close the stream. (Suppress errors, as fclose triggers fflush.)     $this->assertTrue(fclose($handle), 'Able to close file using the read_only stream wrapper.');
    // Test the rename() function     $this->assertFalse(@rename($uri$this->scheme . '://newname.txt'), 'Unable to rename files using the read-only stream wrapper.');
    // Test the unlink() function     $this->assertTrue(@$file_system->unlink($uri), 'Able to unlink file using read-only stream wrapper.');
    $this->assertFileExists($filepath);

    // Test the mkdir() function by attempting to create a directory.     $dirname = $this->randomMachineName();
    $dir = $site_path . '/files/' . $dirname;
    
/** * @return void */
    protected function doWrite(string $message, bool $newline)
    {
        if ($newline) {
            $message .= \PHP_EOL;
        }

        @fwrite($this->stream, $message);

        fflush($this->stream);
    }

    /** * Returns true if the stream supports colorization. * * Colorization is disabled if not supported by the stream: * * This is tricky on Windows, because Cygwin, Msys2 etc emulate pseudo * terminals via named pipes, so we can only check the environment. * * Reference: Composer\XdebugHandler\Process::supportsColor * https://github.com/composer/xdebug-handler * * @return bool true if the stream supports colorization, false otherwise */

    );

    // Write to the start of the file, and truncate it to that length.     fseek( $fp, 0 );
    $bytes = fwrite( $fp$new_file_data );

    if ( $bytes ) {
        ftruncate( $fpftell( $fp ) );
    }

    fflush( $fp );
    flock( $fp, LOCK_UN );
    fclose( $fp );

    return (bool) $bytes;
}

/** * Updates the htaccess file with the current rules if it is writable. * * Always writes to the file if it exists and is writable to ensure that we * blank out old rules. * * @since 1.5.0 * * @global WP_Rewrite $wp_rewrite WordPress rewrite component. * * @return bool|null True on write success, false on failure. Null in multisite. */
/** * @return void */
    protected function doWrite(string $message, bool $newline)
    {
        if ($newline) {
            $message .= \PHP_EOL;
        }

        @fwrite($this->stream, $message);

        fflush($this->stream);
    }

    /** * Returns true if the stream supports colorization. * * Colorization is disabled if not supported by the stream: * * This is tricky on Windows, because Cygwin, Msys2 etc emulate pseudo * terminals via named pipes, so we can only check the environment. * * Reference: Composer\XdebugHandler\Process::supportsColor * https://github.com/composer/xdebug-handler * * @return bool true if the stream supports colorization, false otherwise */


            $totalBytesWritten += $bytesWritten;
        }
    }

    /** * Flushes the contents of the stream (empty it) and set the internal pointer to the beginning. */
    public function flush(): void
    {
        fflush($this->in);
    }

    /** * Performs any initialization needed. */
    abstract public function initialize(): void;

    public function terminate(): void
    {
        $this->stream = $this->out = $this->in = null;
    }

    
Home | Imprint | This part of the site doesn't use cookies.