如何检查$data=file_get_contents(";php://stdin")是空的吗?

如何检查$data=file_get_contents(";php://stdin")是空的吗?,php,Php,我如何检查 $data = file_get_contents("php://stdin"); 是空的,比如当一个人应该传递一个参数但没有传递时 我有一个文件test\u cmd.php: #!/usr/bin/php <?php $data = file_get_contents("php://stdin"); echo $data; 我明白了 然而,当我跑步时: $ test_cmd.php 控制台等待文本输入,我不想这样

我如何检查

$data = file_get_contents("php://stdin");
是空的,比如当一个人应该传递一个参数但没有传递时



我有一个文件
test\u cmd.php

#!/usr/bin/php
<?php

   $data = file_get_contents("php://stdin");
   echo $data;
我明白了

然而,当我跑步时:

$ test_cmd.php
控制台等待文本输入,我不想这样做。我想显示
用法
帮助

如何更正此问题?

尝试以下方法:

if($filecontent = file_get_contents("php://stdin") !== false)
{
   // do stuff here
}

尝试使用posix_isatty

if (posix_isatty(STDIN))
{
    die("Please don't run me interactively!");
}
else
{
    echo file_get_contents('php://stdin');
}

快速测试似乎有效。过一会儿我将对它进行全面测试。
if($filecontent = file_get_contents("php://stdin") !== false)
{
   // do stuff here
}
if (posix_isatty(STDIN))
{
    die("Please don't run me interactively!");
}
else
{
    echo file_get_contents('php://stdin');
}