/** * The main interactive loop * * @author ccheever * @author dcorson */ function interactive_loop() { extract($GLOBALS); while (!feof($this->_handle)) { // indicate to phpsh (parent process) that we are ready for more input fwrite($this->_comm_handle, "ready\n"); // multiline inputs are encoded to one line $buffer_enc = fgets($this->_handle, $this->_MAX_LINE_SIZE); $buffer = stripcslashes($buffer_enc); $err_msg = ''; if ($this->do_undefined_function_check) { $undefd_func = $this->undefined_function_check($buffer); if ($undefd_func) { $err_msg = 'Not executing input: Possible call to undefined function ' . $undefd_func . "()\n" . 'See /etc/phpsh/config.sample to disable UndefinedFunctionCheck.'; } } if ($err_msg) { if ($this->do_color) { echo "[31m"; // red } echo $err_msg; if ($this->do_color) { echo "[0m"; } echo "\n"; continue; } // evaluate what the user entered if ($this->do_color) { echo "[33m"; // yellow } try { $evalue = eval($buffer); } catch (Exception $e) { // unfortunately, almost all exceptions that aren't explicitly thrown // by users are uncatchable :( fwrite(STDERR, 'Uncaught exception: ' . get_class($e) . ': ' . $e->getMessage() . "\n"); $evalue = null; } if ($buffer != "xdebug_break();\n") { ___phpsh___eval_completed(); } // if any value was returned by the evaluated code, echo it if (isset($evalue)) { if ($this->do_color) { echo "[36m"; // cyan } echo ___phpsh___pretty_print($evalue); } // set $_ to be the value of the last evaluated expression $_ = $evalue; // back to normal for prompt if ($this->do_color) { echo "[0m"; } // newline so we end cleanly echo "\n"; } }
/** * The main interactive loop * * @author ccheever * @author dcorson */ function interactive_loop() { extract($GLOBALS); // python spawned-processes ignore SIGPIPE by default, this makes sure // the php process exits when the terminal is closed pcntl_signal(SIGPIPE, SIG_DFL); while (!feof($this->_handle)) { // indicate to phpsh (parent process) that we are ready for more input fwrite($this->_comm_handle, "ready\n"); // multiline inputs are encoded to one line $buffer_enc = fgets($this->_handle, $this->_MAX_LINE_SIZE); $buffer = stripcslashes($buffer_enc); $err_msg = ''; if ($this->do_undefined_function_check) { $undefd_func = $this->undefined_function_check($buffer); if ($undefd_func) { $err_msg = 'Not executing input: Possible call to undefined function ' . $undefd_func . "()\n" . 'See /etc/phpsh/config.sample to disable UndefinedFunctionCheck.'; } } if ($err_msg) { if ($this->do_color) { echo "[31m"; // red } echo $err_msg; if ($this->do_color) { echo "[0m"; } echo "\n"; continue; } // evaluate what the user entered if ($this->do_color) { echo "[33m"; // yellow } if ($this->fork_every_command) { $parent_pid = posix_getpid(); $pid = pcntl_fork(); $evalue = null; if ($pid) { pcntl_wait($status); } else { try { $evalue = eval($buffer); } catch (Exception $e) { // unfortunately, almost all exceptions that aren't explicitly // thrown by users are uncatchable :( fwrite(STDERR, 'Uncaught exception: ' . get_class($e) . ': ' . $e->getMessage() . "\n"); $evalue = null; } // if we are still alive.. $childpid = posix_getpid(); fwrite($this->_comm_handle, "child {$childpid}\n"); } } else { try { $evalue = eval($buffer); } catch (Exception $e) { // unfortunately, almost all exceptions that aren't explicitly thrown // by users are uncatchable :( fwrite(STDERR, 'Uncaught exception: ' . get_class($e) . ': ' . $e->getMessage() . "\n"); $evalue = null; } } if ($buffer != "xdebug_break();\n") { ___phpsh___eval_completed(); } // if any value was returned by the evaluated code, echo it if (isset($evalue)) { if ($this->do_color) { echo "[36m"; // cyan } echo ___phpsh___pretty_print($evalue); } // set $_ to be the value of the last evaluated expression $_ = $evalue; // back to normal for prompt if ($this->do_color) { echo "[0m"; } // newline so we end cleanly echo "\n"; } }