Closed
Description
Description
XDG Base Directory is a specification that defines a list of directories where applications should store configs/data/caches. It is not required to follow, but many applications support it today.
For PHP, the location of .php_history
, a file storing command line history in the REPL (php -a
), is fixed to home directory.
ext/readline/readline_cli.c:
#ifndef PHP_WIN32
history_file = tilde_expand("~/.php_history");
#else
spprintf(&history_file, MAX_PATH, "%s/.php_history", getenv("USERPROFILE"));
#endif
There are several ways to support XDG Base Directory:
- Change path of
.php_history
to$XDG_DATA_HOME/php/history
. If$XDG_DATA_HOME
is not defined, use$HOME/.local/share
instead. - Change default path of
.php_history
to$XDG_DATA_HOME/php/history
only if$XDG_DATA_HOME
is defined. If not, use$HOME/.php_history
as before. - Introduce a new environment variable to set history file path like
$PHP_HISTFILE
. If$PHP_HISTFILE
is not set, use$HOME/.php_history
as before.