本文整理汇总了PHP中posix_ttyname函数的典型用法代码示例。如果您正苦于以下问题:PHP posix_ttyname函数的具体用法?PHP posix_ttyname怎么用?PHP posix_ttyname使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了posix_ttyname函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testInstance
/**
* @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);
}
示例2: getDetails
/**
* 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;
}
示例3: hasFormattingCodes
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;
}
示例4: getTTYSize
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]);
}
示例5: resetStdFd
/**
* 关闭标准输入输出
* @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+");
}
示例6: checkTty
/**
* 检查控制终端是否已经关闭, 如果控制终端关闭,则停止打印数据到终端(发送平滑重启信号)
* @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;
}
}
示例7: instance
/**
* 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];
}
示例8: var_dump
<?php
var_dump(posix_ttyname(STDIN));
var_dump(posix_ttyname(STDERR));
var_dump(posix_ttyname(STDOUT));
?>
===DONE===
示例9: array
<?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));
}
示例10: var_dump
<?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===
示例11: posix_uname
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);
示例12: ttyname
/**
* Determine terminal device name
*
* @param mixed $fd
*
* @return string
*/
public function ttyname($fd) : string
{
return posix_ttyname($fd);
}
示例13: server_echo
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;
}
}
示例14: ttyname
/**
* Get Terminal Device Name
*
* @param int $fd The file descriptor
*
* @return string
*/
public function ttyname($fd)
{
return posix_ttyname($fd);
}
示例15: checkTty
/**
* 检查控制终端是否已经关闭, 如果控制终端关闭,则停止打印数据到终端(发送平滑重启信号)
* @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;
}
}