PHP is_writable('php://stdout');返回假,替代项


PHP is_writable('php://stdout'); returns false, alternatives?

我有一个字符串,我需要检查这个字符串是否表示可写文件或输出流/缓冲区。

is_writable()不适用于标准输出,仅适用于真实文件。

哪种方法适合检查php://stdout

也尝试过stream_is_local(),但它返回true,并带有php://stdout aaa和php://xxx

我显然可以尝试这样的事情:

$file = @fopen('php://stdout', 'w');
if (!$file) {
    throw new Exception();
}

但我想知道是否有更优雅的方式?

试试下面的代码:

is_resource(STDOUT); //true
fclose(STDOUT);
is_resource(STDOUT); // false