From 8336b4c91b6f2c572393f2d7e0cdc6b3bb9f5c46 Mon Sep 17 00:00:00 2001 From: Greyson Fischer Date: Mon, 20 May 2013 02:26:28 -0400 Subject: [PATCH 1/3] Added libedit download/compile --- src/build/compile.sh | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/src/build/compile.sh b/src/build/compile.sh index 6c433c07dd..650be90b1a 100755 --- a/src/build/compile.sh +++ b/src/build/compile.sh @@ -4,6 +4,7 @@ COMPILER_VERSION="0.12" PHP_VERSION="5.4.15" ZEND_VM="GOTO" +LIBEDIT_VERSION="0.3" ZLIB_VERSION="1.2.8" PTHREADS_VERSION="e5d95dfb847c8963c100bd4fb601dde41e0b75d1" CURL_VERSION="curl-7_30_0" @@ -36,6 +37,21 @@ wget http://php.net/get/php-$PHP_VERSION.tar.gz/from/this/mirror -q -O - | tar - mv php-$PHP_VERSION php echo " done!" +#libedit +echo -n "[libedit] downloading $LIBEDIT_VERSION..." +wget http://download.sourceforge.net/project/libedit/libedit/libedit-$LIBEDIT_VERSION/libedit-$LIBEDIT_VERSION.tar.gz -q -O - | tar -zx >> "$DIR/install.log" 2>&1 +echo -n " checking..." +cd libedit +CFLAGS=-fPIC ./configure --prefix="$DIR/install_data/php/ext/libedit" --enable-static >> "$DIR/install.log" 2>&1 +echo -n " compiling..." +make >> "$DIR/install.log" 2>&1 +echo -n " installing..." +make install >> "$DIR/install.log" 2>&1 +echo -n " cleaning..." +cd .. +rm -r -f ./libedit +echo " done!" + #zlib echo -n "[zlib] downloading $ZLIB_VERSION..." wget http://zlib.net/zlib-$ZLIB_VERSION.tar.gz -q -O - | tar -zx >> "$DIR/install.log" 2>&1 @@ -103,6 +119,7 @@ rm -f ./configure >> "$DIR/install.log" 2>&1 --exec-prefix="$DIR/php5" \ --with-curl="$DIR/install_data/php/ext/curl" \ --with-zlib="$DIR/install_data/php/ext/zlib" \ +--with-libedit="$DIR/install_data/php/ext/libedit" \ --disable-libxml \ --disable-xml \ --disable-dom \ From c6121e88bf7134ad176df0c824b3435057d8e52d Mon Sep 17 00:00:00 2001 From: Greyson Fischer Date: Mon, 20 May 2013 16:16:26 -0400 Subject: [PATCH 2/3] Optionally disabled libedit based on results of compile --- src/build/compile.sh | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/src/build/compile.sh b/src/build/compile.sh index 650be90b1a..4a69c1918f 100755 --- a/src/build/compile.sh +++ b/src/build/compile.sh @@ -44,9 +44,14 @@ echo -n " checking..." cd libedit CFLAGS=-fPIC ./configure --prefix="$DIR/install_data/php/ext/libedit" --enable-static >> "$DIR/install.log" 2>&1 echo -n " compiling..." -make >> "$DIR/install.log" 2>&1 -echo -n " installing..." -make install >> "$DIR/install.log" 2>&1 +if make >> "$DIR/install.log" 2>&1; then + echo -n " installing..." + make install >> "$DIR/install.log" 2>&1 + HAVE_LIBEDIT="--with-libedit=$DIR/install_data/php/ext/libedit" +else + echo -n " disabling..." + HAVE_LIBEDIT="--without-libedit" +fi echo -n " cleaning..." cd .. rm -r -f ./libedit @@ -119,7 +124,7 @@ rm -f ./configure >> "$DIR/install.log" 2>&1 --exec-prefix="$DIR/php5" \ --with-curl="$DIR/install_data/php/ext/curl" \ --with-zlib="$DIR/install_data/php/ext/zlib" \ ---with-libedit="$DIR/install_data/php/ext/libedit" \ +"$HAVE_LIBEDIT" \ --disable-libxml \ --disable-xml \ --disable-dom \ From ff8de264c078aff856e62daf3838829bbd9e275b Mon Sep 17 00:00:00 2001 From: Greyson Fischer Date: Mon, 20 May 2013 02:58:32 -0400 Subject: [PATCH 3/3] Added "readline" support using libedit. --- src/API/ConsoleAPI.php | 43 +++++++++++++++++++++++++++--------------- 1 file changed, 28 insertions(+), 15 deletions(-) diff --git a/src/API/ConsoleAPI.php b/src/API/ConsoleAPI.php index c511feb7c0..9a32769edc 100644 --- a/src/API/ConsoleAPI.php +++ b/src/API/ConsoleAPI.php @@ -297,31 +297,44 @@ class ConsoleLoop extends Thread{ public $stop; public $base; public $ev; + public $fp; public function __construct(){ $this->line = false; $this->stop = false; $this->start(); } - + public function stop(){ $this->stop = true; } - - public function readLine($fp, $events = null){ - $line = trim(fgets($fp)); - if($line != ""){ - $this->line = $line; - } - } - + + private function readLine(){ + if( $this->fp ){ + $line = trim( fgets( $this->fp ) ); + } else { + $line = trim( readline( "" ) ); + if( $line != "" ){ + readline_add_history( $line ); + } + } + + return $line; + } + public function run(){ - $fp = fopen("php://stdin", "r"); - while($this->stop === false and ($line = fgets($fp)) !== false){ - $this->line = $line; - $this->wait(); - $this->line = false; + if( ! extension_loaded( 'readline' ) ){ + $this->fp = fopen( "php://stdin", "r" ); + } + + while( $this->stop === false ) { + $this->line = $this->readLine(); + $this->wait(); + $this->line = false; } - @fclose($fp); + + if( ! $this->haveReadline ) { + @fclose($fp); + } exit(0); } }