Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature request: XDG Base Directory for .php_history #8546

Open
nsfisis opened this issue May 13, 2022 · 1 comment · May be fixed by #12587
Open

Feature request: XDG Base Directory for .php_history #8546

nsfisis opened this issue May 13, 2022 · 1 comment · May be fixed by #12587

Comments

@nsfisis
Copy link

nsfisis commented May 13, 2022

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.
paulfedorow added a commit to paulfedorow/php-src that referenced this issue Nov 1, 2023
Resolves phpGH-8546.

To keep existing installations working the code first checks if a
history file already exists at `~/.php_history`. If it does, then
everything works as before.

If `~/.php_history` does not exist, we check whether the system supports
the XDG Base Directory Specification. If it doesn't we continue using
`~/.php_history`; otherwise, we use a path that conforms to the XDG Base
Directory Specification.

We detect support for XDG Base Directory Specification by checking for
environment variables that start with the `XDG_` prefix. This is
analogous to what Composer does:
composer/composer#1407

The specification can be found here:
https://specifications.freedesktop.org/basedir-spec/basedir-spec-latest.html
paulfedorow added a commit to paulfedorow/php-src that referenced this issue Nov 1, 2023
Resolves phpGH-8546.

To keep existing installations working the code first checks if a
history file already exists at `~/.php_history`. If it does, then
everything works as before.

If `~/.php_history` does not exist, we check whether the system supports
the XDG Base Directory Specification. If it doesn't we continue using
`~/.php_history`; otherwise, we use a path that conforms to the XDG Base
Directory Specification.

We detect support for XDG Base Directory Specification by checking for
environment variables that start with the `XDG_` prefix. This is
analogous to what Composer does:
composer/composer#1407

The specification can be found here:
https://specifications.freedesktop.org/basedir-spec/basedir-spec-latest.html
@bdsoha
Copy link

bdsoha commented Jan 17, 2024

Why is this not being defined as an environment variable with a default fallback?

Other languages use such a lookup strategy (see 2 examples below):

  • node: NODE_REPL_HISTORY
  • less: LESSHISTFILE

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants