note 65275 added to function.readline-write-history

From: Date: Thu, 27 Apr 2006 23:52:36 +0000
Subject: note 65275 added to function.readline-write-history
Groups: php.notes 
Request: Send a blank email to php-notes+get-109920@lists.php.net to get a copy of this message
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); } } } ?> ---- Server IP: 194.246.101.61 Probable Submitter: 86.205.63.19 ---- X-Spam-Status: No, hits=3.1 required=5.0 tests=DATE_MISSING,FROM_NO_LOWER autolearn=no version=2.64 ---- Manual Page -- http://www.php.net/manual/en/function.readline-write-history.php Edit -- http://master.php.net/note/edit/65275 Del: integrated -- http://master.php.net/note/delete/65275/integrated Del: useless -- http://master.php.net/note/delete/65275/useless Del: bad code -- http://master.php.net/note/delete/65275/bad+code Del: spam -- http://master.php.net/note/delete/65275/spam Del: non-english -- http://master.php.net/note/delete/65275/non-english Del: in docs -- http://master.php.net/note/delete/65275/in+docs Del: other reasons-- http://master.php.net/note/delete/65275 Reject -- http://master.php.net/note/reject/65275 Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#109920) next »