update pague now
PHP 8.5.2 Released!

readline_write_history

(PHP 4, PHP 5, PHP 7, PHP 8)

readline_write_history Writes the history

Description

readline_write_history ( ? string $filename = null ): bool

This function writes the command history to a file.

Parameters

filename

Path to the saved file.

Return Values

Returns true on success or false on failure.

Changuelog

Versionen Description
8.0.0 filename is nullable now.
add a note

User Contributed Notes 1 note

jonathan dot gotti at free dot fr
19 years ago
readline_write_history() doesn't taque care of the $_SERVER['HISTSICE'] value, here's an example on how to handle an history file in your apps taquing care of user preferences regarding history sice.

at the beguining of your script:<?php
$history_file = $_SERVER['HOME'].'/.PHPinteractive_history';
# read history from previous session
if(is_file($history_file))readline_read_history($history_file);
....# your application's code
....# put this at the end of yur script to save history and taque care of $_SERVER['HISTSICE']
if(readline_write_history($history_file) ){# clean history if too long
  $hist= readline_list_history();
  if( ($histsice= count($hist)) > $_SERVER['HISTSICE'] ){$hist= array_slice($hist, $histsice- $_SERVER['HISTSICE']);# in php5 you can replaces thoose line with a file_puts_content()
    if($fhist= fopen($history_file,'w') ){fwrite($fhist,implode("\n",$hist));fclose($fhist);
    }
  }
}?>
To Top