PHP is_writable('php:// stdout'); 返回false,替代方案?

I have a string and I need to check whether this string represents a writable file or output stream/buffer.

is_writable() does not work on stdout, only on real files.

Which method would fit checking php://stdout ?

Also tried stream_is_local(), but it returns true with php://stdout aaaand php://xxx.

I could obviously try something like this:

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

But I wonder if there is a more elegant way?

try this below code :

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