php中 ob_start等函数截取标准输出的方法_PHP
最近在用PHP在cli下开发一款软件,遇到了这样的问题。我想将PHP脚本中输出的东西收集在一起,于是使用了ob_start和ob_end_flush这两个函数,确实有达到收集输出内容的作用,但同时也将这些打印到了控制台界面中。我想问的是有没有办法,阻止PHP像控制台输出信息。该软件原则上是不允许向控制台打印任何东西的。
php-cli本身脱离web服务器执行脚本,我不知道你现在获取到的数据是怎么拿到的?如果你不是通过cli执行php程序返回的值拿到的,那么可以使用ob_get_clean()
他会获取缓存内容后清除缓存区,这样可以达到你说的不显示到显示界面的效果
当然你也可以获取到缓冲区内容,然后清空(控制不要输出到控制台),然后将内容falsh到web服务器上做处理
按照以上方法已经搞定了。之前有用过这个系列的函数,太久不用,有些忘了。
现在在做的是一个基于PHP的多进程HTTP动态服务器。毕业论文,试验品而已,没什么实用性。
php-cgi程序执行结果是标准输入输出,所以只能用获取标准输入输出的方式截取输出结果,管道应该也可以,不过我不会
以上所述就是本文的全部内容了,希望大家能够喜欢。

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



PHP 8.4 brings several new features, security improvements, and performance improvements with healthy amounts of feature deprecations and removals. This guide explains how to install PHP 8.4 or upgrade to PHP 8.4 on Ubuntu, Debian, or their derivati

To work with date and time in cakephp4, we are going to make use of the available FrozenTime class.

CakePHP is an open-source framework for PHP. It is intended to make developing, deploying and maintaining applications much easier. CakePHP is based on a MVC-like architecture that is both powerful and easy to grasp. Models, Views, and Controllers gu

To work on file upload we are going to use the form helper. Here, is an example for file upload.

Visual Studio Code, also known as VS Code, is a free source code editor — or integrated development environment (IDE) — available for all major operating systems. With a large collection of extensions for many programming languages, VS Code can be c

CakePHP is an open source MVC framework. It makes developing, deploying and maintaining applications much easier. CakePHP has a number of libraries to reduce the overload of most common tasks.

This tutorial demonstrates how to efficiently process XML documents using PHP. XML (eXtensible Markup Language) is a versatile text-based markup language designed for both human readability and machine parsing. It's commonly used for data storage an

JWT is an open standard based on JSON, used to securely transmit information between parties, mainly for identity authentication and information exchange. 1. JWT consists of three parts: Header, Payload and Signature. 2. The working principle of JWT includes three steps: generating JWT, verifying JWT and parsing Payload. 3. When using JWT for authentication in PHP, JWT can be generated and verified, and user role and permission information can be included in advanced usage. 4. Common errors include signature verification failure, token expiration, and payload oversized. Debugging skills include using debugging tools and logging. 5. Performance optimization and best practices include using appropriate signature algorithms, setting validity periods reasonably,
