是否等于fputs(STDout)? [英] does echo equal fputs( STDout )?

查看:228
本文介绍了是否等于fputs(STDout)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

echo等于fputs( STDOUT ),还是echo写入不同的流?我已经使用PHP一段时间了,但是我不太了解较低级别的实际情况.

Does echo equal fputs( STDOUT ), or does echo write to a different stream? I've used PHP for a while now, but I don't know very well what's actually happening on a lower level.

推荐答案

根据 PHP关于包装程序的手册页,答案是否".

php://输出

php://output

php://output是一个只写流,它允许您写入 输出缓冲区机制与print()和echo()相同.

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上测试):

This script outputs (tested on PHP 5.2.13, windows):

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

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

i.e. writing to STDOUT directly bypasses ob handlers.

这篇关于是否等于fputs(STDout)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆