php - echo 是否等于 fputs(STDout)?

标签 php stream stdout

echo 等于 fputs( STDOUT ),还是 echo 写入不同的流?我已经使用 PHP 一段时间了,但我不太清楚在较低级别上实际发生了什么。

最佳答案

根据PHP's manual page on wrappers ,答案是否定的。

php://output

php://output is a write-only stream that allows you to write to the output buffer mechanism in the same way as print() and echo().

printecho 写入 php://output 流,而 fputs(STDOUT) 写入php://stdout.

我做了一个小测试:

<?php

$output = fopen('php://output', 'w');
ob_start();

echo "regular echo\n";
fwrite(STDOUT, "writing to stdout directly\n");
fwrite($output, "writing to php://output directly\n");

$ob_contents = ob_get_clean();
print "ob_contents: $ob_contents\n";

此脚本输出(在 PHP 5.2.13,windows 上测试):

writing to stdout directly
ob_contents: regular echo
writing to php://output directly

即写入 STDOUT 直接绕过 ob 处理程序。

关于php - echo 是否等于 fputs(STDout)?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7027902/

相关文章:

java - 在 Java 中将流转换为字符串

c# - 由于事先不知道长度,因此如何录制到Stream中?

multithreading - 在 Perl 中是否有线程安全的打印方式?

go - 在 Go 中,是否可以写入控制台并读回?

php - sql left join 不工作

php - 从 PHP 中的图像中裁剪空白

java - 'ZipException : invalid code lengths set' when streaming input file to Apache-POI

c - stdin、stdout 和 stderr 到标准输入和标准输出的实际分配

javascript - jquery (ajax) click 使 php 脚本运行多次

php - 自定义论坛功能未返回正确的 ID?