php 的 STDOUT , php://stdout , php://output 在cgi上的区别?
大家好:
我初学php ,遇到一个问题,我当前服务器系统是linux , 上面运行apache 的cgi 来执行用户的请求。
假设我建立php 的一个测试文件test.php,其中就一句话,fwrite(STDOUT , "this is a test");
我通过ie浏览器的地址栏执行此测试程序,无法得到正常输出,但我在服务器端linux shell 下直接运行
此test.php 能看到输出。
我又修改test.php 如下内容:$out=fopen("php://stdout", 'w'); fwrite($out , "this is a test");
情况依然如上,ie 浏览器无法正常浏览到内容,但shell 下能正常看到输出。
我又修改test.php 如下内容:$out=fopen("php://output",'w'); fwrite($out , "this is a test");
这次 ie 浏览器上能看到正常的输出,shell 下也能看到正常输出。
我又尝试修改 test.php 如下: echo("this is a test");
这次ie 正常,shell 下也正常。
我的问题是, STDOUT , php://stdout , php://output 这3个有什么区别,为什么除了 php://output
以外 apache 没能把程序的标准输出给重定向到正确的cgi 上?
回复讨论(解决方案)
STDOUT是CLI方式专用常量,相当于fopen('php://stdout', 'w');
也就是说CLI才有效
php://out 等同于echo/print
详见手册中《php://》和《PHP 的命令行模式》两节
可能是apache关闭了stdout,参考 解决 php-fpm php://stdout 命令行 打印 失效问题 -- http://blog.csdn.net/zhangrui_fslib_org/article/details/49681563
可能是apache关闭了stdout,参考 解决 php-fpm php://stdout 命令行 打印 失效问题 -- http://blog.csdn.net/zhangrui_fslib_org/article/details/49681563

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

Laravel simplifies handling temporary session data using its intuitive flash methods. This is perfect for displaying brief messages, alerts, or notifications within your application. Data persists only for the subsequent request by default: $request-

The PHP Client URL (cURL) extension is a powerful tool for developers, enabling seamless interaction with remote servers and REST APIs. By leveraging libcurl, a well-respected multi-protocol file transfer library, PHP cURL facilitates efficient execution of various network protocols, including HTTP, HTTPS, and FTP. This extension offers granular control over HTTP requests, supports multiple concurrent operations, and provides built-in security features.

Laravel provides concise HTTP response simulation syntax, simplifying HTTP interaction testing. This approach significantly reduces code redundancy while making your test simulation more intuitive. The basic implementation provides a variety of response type shortcuts: use Illuminate\Support\Facades\Http; Http::fake([ 'google.com' => 'Hello World', 'github.com' => ['foo' => 'bar'], 'forge.laravel.com' =>

Do you want to provide real-time, instant solutions to your customers' most pressing problems? Live chat lets you have real-time conversations with customers and resolve their problems instantly. It allows you to provide faster service to your custom

Article discusses late static binding (LSB) in PHP, introduced in PHP 5.3, allowing runtime resolution of static method calls for more flexible inheritance.Main issue: LSB vs. traditional polymorphism; LSB's practical applications and potential perfo

Laravel's service container and service providers are fundamental to its architecture. This article explores service containers, details service provider creation, registration, and demonstrates practical usage with examples. We'll begin with an ove

PHP logging is essential for monitoring and debugging web applications, as well as capturing critical events, errors, and runtime behavior. It provides valuable insights into system performance, helps identify issues, and supports faster troubleshoot

The article discusses adding custom functionality to frameworks, focusing on understanding architecture, identifying extension points, and best practices for integration and debugging.
