/** * @dataProvider getGlobalTermAndTermAndTermFile */ public function testInstance($global = null, $term = null, $termFileName = 'xterm-256color') { $tty = posix_ttyname(STDOUT); $terminal = TerminalTestUtil::getTerminalInstance($global, $tty, $term, $termFileName); $this->assertEquals($tty, $terminal->getTty()); $this->assertEquals($term, $terminal->getTerm()); $this->assertNull($terminal->getPreviousConfig()); $this->assertEquals('normal', $terminal->getMode()); $this->assertEquals($term, $terminal->getTerminfo()->getTerm()); $this->assertSame($terminal, $terminal->getCursor()->getTerminal()); $this->assertSame($terminal, $terminal->getScreen()->getTerminal()); $oldInput = $terminal->getInput(); $oldOutput = $terminal->getOutput(); $this->assertEquals('php://stdin', $terminal->getInput()->getSource()); $this->assertEquals('rb', $terminal->getInput()->getMode()); $this->assertEquals('php://stdout', $terminal->getOutput()->getSource()); $this->assertEquals('wb', $terminal->getOutput()->getMode()); $newInput = new FileInputStream('php://memory', 'rb'); $newOutput = new FileOutputStream('php://memory', 'wb'); $terminal->setInput($newInput); $terminal->setOutput($newOutput); $this->assertEquals('php://memory', $terminal->getInput()->getSource()); $this->assertEquals('rb', $terminal->getInput()->getMode()); $this->assertEquals('php://memory', $terminal->getOutput()->getSource()); $this->assertEquals('wb', $terminal->getOutput()->getMode()); $terminal->setInput($oldInput); $terminal->setOutput($oldOutput); }
/** * Get terminal details * * @return string */ public function getDetails() { if (!$this->details) { $this->details = function_exists('posix_ttyname') ? @posix_ttyname(STDOUT) : "Can't retrieve terminal details"; } return $this->details; }
public static function hasFormattingCodes() { if (self::$formattingCodes === null) { $opts = getopt("", ["enable-ansi", "disable-ansi"]); //if(isset($opts["disable-ansi"])){ // self::$formattingCodes = false; //}else{ self::$formattingCodes = (Utils::getOS() !== "win" and getenv("TERM") != "" and (!function_exists("posix_ttyname") or !defined("STDOUT") or posix_ttyname(STDOUT) !== false) or isset($opts["enable-ansi"])); //} } return self::$formattingCodes; }
private function getTTYSize() { if (!posix_isatty(STDOUT)) { return false; } $ttyName = posix_ttyname(STDOUT); $builder = new ProcessBuilder(); $process = $builder->setPrefix('stty')->setArguments(array('-f', $ttyName, 'size'))->getProcess(); try { $process->mustRun(); } catch (ProcessFailedException $e) { return false; } $output = $process->getOutput(); if (!preg_match('~^(\\d+)\\s+(\\d+)$~', $output, $match)) { return false; } return array($match[1], $match[2]); }
/** * 关闭标准输入输出 * @return void */ protected static function resetStdFd($force = false) { // 如果此进程配置是no_debug,则关闭输出 if (!$force) { // 开发环境不关闭标准输出,用于调试 if (Lib\Config::get('workerman.debug') == 1 && posix_ttyname(STDOUT)) { return; } } global $STDOUT, $STDERR; @fclose(STDOUT); @fclose(STDERR); // 将标准输出重定向到/dev/null $STDOUT = fopen('/dev/null', "rw+"); $STDERR = fopen('/dev/null', "rw+"); }
/** * 检查控制终端是否已经关闭, 如果控制终端关闭,则停止打印数据到终端(发送平滑重启信号) * @return void */ public function checkTty() { if (!$this->terminalClosed && !@posix_ttyname(STDOUT)) { $this->resetFd(); // 日志 $this->notice("terminal closed and reset workers fd"); // worker重启时会检测终端是否关闭 $this->sendSignalToAllWorker(SIGTTOU); // 设置标记 $this->terminalClosed = true; } }
/** * Creates a new terminal instance. * * @param string $tty The tty name. * @param string $term The terminal name. * @return Terminal The terminal instance. */ public static function instance($tty = null, $term = null) { if (null === $tty) { $tty = posix_ttyname(STDOUT); } $key = md5($tty . '/' . $term); if (!isset(self::$instances[$key])) { self::$instances[$key] = new self($tty, $term); } return self::$instances[$key]; }
<?php var_dump(posix_ttyname(STDIN)); var_dump(posix_ttyname(STDERR)); var_dump(posix_ttyname(STDOUT)); ?> ===DONE===
<?php echo "*** Test substituting argument 1 with boolean values ***\n"; $variation_array = array('lowercase true' => true, 'lowercase false' => false, 'uppercase TRUE' => TRUE, 'uppercase FALSE' => FALSE); foreach ($variation_array as $var) { var_dump(posix_ttyname($var)); }
<?php var_dump(posix_ttyname()); // param missing var_dump(posix_ttyname(0)); // param not a ressource var_dump(posix_ttyname(imagecreate(1, 1))); // wrong resource type ?> ===DONE===
echo "posix_setpgid failed\n"; } $uname = posix_uname(); echo "uname=\n"; print_r($uname); $times = posix_times(); foreach ($times as $k => $v) { if ($v < 0) { echo "times[{$k}] is negative\n"; } else { echo "times[{$k}] is greater than or equal to 0\n"; } } $ctermid = posix_ctermid(); echo "ctermid={$ctermid}\n"; $ttyname = posix_ttyname(1); echo "ttyname for fd 1 = {$ttyname}\n"; $isatty = posix_isatty(1); echo "isatty for fd 1 = {$isatty}\n"; $cwd = posix_getcwd(); if (file_exists($cwd)) { echo "posix_getcwd succeeded\n"; } else { echo "posix_getcwd failed\n"; } // make sure the file we use for testing ain't there already $testfile = "/tmp/phpoo_test_fifo204982"; if (file_exists($testfile)) { unlink($testfile); } $mkfifo = posix_mkfifo($testfile, 0);
/** * Determine terminal device name * * @param mixed $fd * * @return string */ public function ttyname($fd) : string { return posix_ttyname($fd); }
public function server_echo($str, $newline = TRUE) { if ($newline) { $str = "\n" . $str; } $str = $this->time_prefix($str); $this->server_ob[] = $str; $this->server_ob = array_slice($this->server_ob, -20, 20); $server_logpath = $this->log_path . '/server/'; $server_daily_logpath = $server_logpath . '/' . date('Ymd'); if (!is_dir($server_logpath)) { mkdir($server_logpath, 0777); } if (!is_dir($server_daily_logpath)) { mkdir($server_daily_logpath, 0777); } $server_logfile = $server_daily_logpath . '/' . date('YmdH') . '.log'; file_put_contents($server_logfile, $str, FILE_APPEND); if (!$this->server_muted && posix_ttyname(STDOUT)) { echo $str; } }
/** * Get Terminal Device Name * * @param int $fd The file descriptor * * @return string */ public function ttyname($fd) { return posix_ttyname($fd); }
/** * 检查控制终端是否已经关闭, 如果控制终端关闭,则停止打印数据到终端(发送平滑重启信号) * @return void */ public function checkTty() { if (!$this->terminalClosed && !posix_ttyname(STDOUT)) { // 日志 $this->notice("terminal closed and restart worker"); // worker重启时会检测终端是否关闭 $this->sendSignalToAllWorker(SIGHUP); // 设置标记 $this->terminalClosed = true; } }
public static function checkTty() { if (self::$terminalHasClosed) { return; } if (!posix_ttyname(STDOUT)) { self::notice("The terminal is closed ,Server reloading"); self::addToRestartWorkers(array_keys(self::getPidWorkerNameMap())); self::restartWorkers(); self::$terminalHasClosed = true; } }
<?php echo "*** Test by calling method or function with incorrect numbers of arguments ***\n"; $fd = 'foo'; $extra_arg = 'bar'; var_dump(posix_ttyname($fd, $extra_arg)); var_dump(posix_ttyname());
/** * notice,记录到日志 * @param string $msg * @param bool $display * @return void */ public static function notice($msg, $display = false) { Lib\Log::add("Server:" . trim($msg)); if ($display) { if (self::$serviceStatus == self::STATUS_STARTING && @posix_ttyname(STDOUT)) { echo $msg . "\n"; } } }
*/ iconv_set_encoding("input_encoding", "US-ASCII"); // Set the character encoding to "UTF-8" iconv_set_encoding("internal_encoding", "US-ASCII"); // Set the character encoding to "UTF-8" iconv_set_encoding("output_encoding", "US-ASCII"); // Set the character encoding to "UTF-8" error_reporting(E_ALL); // We like error messages , bring em on. set_time_limit(0); // We don't want a time limit. ob_implicit_flush(); // Clear the output buffer. // Recording starting TTY state. $bIsTTYconnection = posix_isatty(STDOUT); $szTTYname = posix_ttyname(STDOUT) || NULL; //*** //*** Declare Global variables //*** $szCRLF = chr(13) . chr(10); // Carriage return + line feed $szCRLFterminator = $szCRLF . $szCRLF; // Shorthand for \r\n\r\n $szPacketTerminator = $szCRLF; // Asterisk packet terminator // for incoming responses from // the Asterisk AMI interface. // After the intitail connection // string from the Asterisk AMI interface // this value is adjusted from // \r\n to \r\n\r\n