>  기사  >  백엔드 개발  >  php://output과 php://stdout의 차이점에 대한 자세한 설명

php://output과 php://stdout의 차이점에 대한 자세한 설명

php中世界最好的语言
php中世界最好的语言원래의
2018-05-16 11:12:462967검색

이번에는 php://output과 php://stdout의 차이점과 php://output과 php://stdout 사용 시 notes가 무엇인지 자세히 설명드리겠습니다. 실제 사례입니다. 일어나서 살펴보세요.

PHP 공식 문서에서 답을 찾으세요. 입력 스트림 php://stdin 및 php://input에 대한 설명은 다음과 같습니다(출력 스트림에 대한 설명이 너무 짧습니다).

php://stdin
php://stdin, php://stdout and php://stderr allow direct access to the corresponding input or output stream of the PHP process. The stream references a duplicate file descriptor, so if you open php://stdin and later close it, you close only your copy of the descriptor-the actual stream referenced by STDIN is unaffected. Note that PHP exhibited buggy behavior in this regard until PHP 5.2.1. It is recommended that you simply use the constants STDIN, STDOUT and STDERR instead of manually opening streams using these wrappers.
php://stdin is read-only, whereas php://stdout and php://stderr are write-only.
php://input
php://input is a read-only stream that allows you to read raw data from the request body. In the case of POST requests, it is preferable to use php://input instead of $HTTP_RAW_POST_DATA as it does not depend on special php.ini directives. Moreover, for those cases where $HTTP_RAW_POST_DATA is not populated by default, it is a potentially less memory intensive alternative to activating always_populate_raw_post_data. php://input is not available with enctype=”multipart/form-data”.

문서는 다음과 같습니다. 두 가지를 직접적으로 설명하지 마십시오. 차이점을 주의 깊게 비교하면 다음 정보를 얻을 수 있습니다. 1. 둘 다 읽기 전용 스트림입니다. 2. php://stdin은 PHP 프로세스의 표준 입력이고 php://input은 다음과 같습니다. 요청 본문의 원본 데이터를 읽는 데 사용됩니다. 이 정보를 통해 둘 사이의 본질적인 차이점을 어떻게 올바르게 이해할 수 있습니까?

php://stdin 프로세스의 입력 프롬프트에 따라 PHP 프로세스의 실행 프로세스를 연관시키고 이를 SAPI의 차이점과 결합하면 둘 사이의 주요 차이점을 얻을 수 있습니다. php://stdin은 PHP 프로세스의 입력 스트림 및 실행 라이프 사이클 데이터가 유입될 수 있습니다(예: CLI의 대화형 입력). php://input은 PHP가 실행될 때 외부 입력 스트림입니다. 한 번 읽으십시오(자세한 내용은 SAPI 구현 참조). 같은 방법으로 php://stdout과 php://output의 차이점을 알 수 있습니다. php://stdout은 PHP 프로세스의 표준 출력 스트림이고 php://output은 반환된 결과 데이터 스트림입니다. .

다음 코드는 결론을 확인하는 데 사용됩니다.

// file: test.php
file_put_contents("php://output", "message sent by output" . PHP_EOL);
file_put_contents("php://stdout", "message sent by stdout" . PHP_EOL);
print("message sent by print" . PHP_EOL);
echo "SAPI:" , PHP_SAPI , PHP_EOL;

명령줄 실행 파일, 출력은 다음과 같습니다.

message sent by output
message sent by stdout
message sent by print
SAPI:cli

브라우저 측 요청, 출력은 다음과 같습니다.

message sent by output
message sent by print
SAPI:fpm-fcgi

명령줄 아래, 표준 출력 PHP 프로세스의 스트림과 결과 출력 스트림은 모두 터미널을 가리키며 모든 메시지가 인쇄됩니다. 브라우저 측에서는 PHP 프로세스의 출력 스트림이 무시되고 결과 데이터 스트림만 웹 서버로 전송됩니다. 동시에 print 및 echo 호출 정보가 실행 결과로 결과 출력 스트림으로 전송되므로 정상적으로 표시됩니다.

이 기사의 사례를 읽은 후 방법을 마스터했다고 생각합니다. 더 흥미로운 정보를 보려면 PHP 중국어 웹사이트의 다른 관련 기사를 주목하세요!

추천 자료:

PHP는 초대형 숫자의 정수 집합을 계산합니다

PHP+ajax 뉴스 데이터 케이스 세부 정보 얻기 구현

위 내용은 php://output과 php://stdout의 차이점에 대한 자세한 설명의 상세 내용입니다. 자세한 내용은 PHP 중국어 웹사이트의 기타 관련 기사를 참조하세요!

성명:
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.