4

One of the improvements in PHP7.1 is that in Windows the readline extension is available out of the box. I'm having trouble using all of the functions though, as they don't all exist. The following code:

$functions = [
    'readline_add_history',
    'readline_callback_handler_install',
    'readline_callback_handler_remove',
    'readline_callback_read_char',
    'readline_clear_history',
    'readline_completion_function',
    'readline_info',
    'readline_list_history',
    'readline_on_new_line',
    'readline_read_history',
    'readline_redisplay',
    'readline_write_history',
    'readline'
];
foreach($functions as $function) {
    echo $function . (function_exists($function) ? ' exists' : ' does not exist') . PHP_EOL;
}

...produces the following output:

readline_add_history exists
readline_callback_handler_install does not exist
readline_callback_handler_remove does not exist
readline_callback_read_char does not exist
readline_clear_history exists
readline_completion_function exists
readline_info exists
readline_list_history does not exist
readline_on_new_line does not exist
readline_read_history exists
readline_redisplay does not exist
readline_write_history exists
readline exists

I can't find any reference in the PHP manual that only a subset of the readline extension's functions are available in Windows.

When I call php_info(), I get the following output:

readline

Readline Support enabled

Readline library WinEditLine

Is there some php.ini configuration setting (or CLI argument) that needs to be made in order to make all functions available? Alternately, is there some other way of making functions such as readline_callback_handler_install() available in Windows, or is the extension only half-baked?

e_i_pi
  • 4,590
  • 4
  • 27
  • 45

2 Answers2

3

Initially I thought that you might have been somehow falling through to an ancient PHP 5.0 which lacks those functions, but failing that I would have to guess that your PHP binary was compiled against an underlying library [or version thereof] that doesn't support the feature that those functions depend on.

Cross-referencing the list of functions that are missing with ext/readline/readline.c I would guess you're missing features corresponding to the constants/features HAVE_RL_CALLBACK_READ_CHAR and HAVE_LIBEDIT defined in ext/readline/config.m4.

TL;DR: Whoever compiled your PHP needs to figure it out. [probably]

Sammitch
  • 30,782
  • 7
  • 50
  • 77
  • I'm using EasyPHP as my dev server, which offers shrink-wrapped PHP binaries. I'll try downloading a thread safe 64 bit directly from windows.php.net and see if that works. – e_i_pi May 04 '18 at 23:08
  • Further investigation seems to indicate that that is, in fact, an official PHP binary that you're using. Further to that, they all seem to have the same problem. :/ – Sammitch May 04 '18 at 23:28
  • True, my investigations show the same. I'm now looking into a workaround, triggering the shutdown handler on SIGINT on Windows. Getting the same solid brick wall there too, what a gip. – e_i_pi May 04 '18 at 23:33
  • Uhh... Windows doesn't have POSIX signals. At all. ¯\\_(ツ)\_/¯ https://stackoverflow.com/questions/3333276/signal-handling-on-windows – Sammitch May 04 '18 at 23:37
  • 1
    Which sucks - it means if I terminate a process via Ctrl-C I can't force rollback on database operations, which can lead to data corruption. Joy. Time to look into running a local *nix instance – e_i_pi May 04 '18 at 23:38
  • 1
    I was just about to suggest spinning up a *nix VM in something like VirtualBox. The further under Windows' hood you try to work with PHP, the more difficulty you're going to have since PHP very much favors the *nix ecosystem. – Sammitch May 04 '18 at 23:41
1

For the record

PHP >= 7.4 to 8.1

yes:

  • readline_add_history
  • readline_clear_history
  • readline_completion_function
  • readline_info
  • readline_list_history
  • readline_read_history
  • readline_write_history
  • readline

no:

  • readline_callback_handler_install
  • readline_callback_handler_remove
  • readline_callback_read_char
  • readline_on_new_line
  • readline_redisplay

readline_list_history was added around during versions 7.2 and 7.3

magallanes
  • 6,583
  • 4
  • 54
  • 55