Search code examples
phpncursespeclphar

Bundle PECL extension in a phar


The PHP ncurses library is not installed on a normal php installation, you must install it as a PECL extension

I would like to bundle it in a php phar app.

Is this possibile and how to do it?


Solution

  • I agree with cweiske's answer.

    I understand why you would be interested in doing this, but the reality is that the pre-requisite of PHP for a .phar means that they will never be a standalone executable. They are like java .jar files. In each case the relevant runtime environment is required.

    The PHP solution suggested is simple:

    if (!extension_loaded('ncurses')) {
        echo "The ncurses Extension is required.  Use PECL or your system package manager to install it.  See http://php.net/ncurses for more information."
        exit;
    }
    

    With that said, if my assumption is correct, whatever program you are trying to create using ncurses, is probably better written in a self contained language that can be compiled into an executable (c, c++).

    Or at least a language that can handle app packaging in a robust and simple way (python, Ruby, Golang). In particular with so much interest in Golang for cross platform tools like Docker, and with terminal libraries like termui, I think you should consider whether PHP is really the right tool for the sort of application you are creating.