PHP: readline_write_history - Manual

downloads | documentation | faq | getting help | mailing lists | reporting bugs | php.net sites | links | conferences | my php.net

search for in the

readline readline_redisplay

Last updated: Fri, 26 Jan 2007

view this page in

# readline_write_history

(PHP 4, PHP 5)

readline_write_history -- Writes the history

## Description

bool readline_write_history ( [string filename] )

This function writes the command history to a file.

add a note User Contributed Notes
readline_write_history
jonathan dot gotti at free dot fr
27-Apr-2006 04:52
`readline_write_history() doesn't take care of the $_SERVER['HISTSIZE'] value, here's an example on how to handle an history file in your apps taking care of user preferences regarding history size.
at the begining 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 take care of $_SERVER['HISTSIZE']
if( readline_write_history($history_file) ){
# clean history if too long
$hist = readline_list_history();
if( ($histsize = count($hist)) > $_SERVER['HISTSIZE'] ){
$hist = array_slice($hist, $histsize - $_SERVER['HISTSIZE']);
# 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);
}
}
}
?>`
add a note
readline readline_redisplay

Last updated: Fri, 26 Jan 2007
show source | credits | stats | sitemap | contact | advertising | mirror sites
Copyright © 2001-2007 The PHP Group
All rights reserved.
This mirror generously provided by: Yahoo! Inc.
Last updated: Sat Mar 10 10:36:09 2007 PST