PHP Velho Oeste 2024

HttpResponse::send

(PECL pecl_http >= 0.10.0)

HttpResponse::sendSend response

설명

static bool HttpResponse::send ([ bool $clean_ob = true ] )

Finally send the entity.

A successful caching attempt will exit PHP, and write a log entry if the INI 설정 http.log.cache is set. "exits"의 의미에 대해서 INI 설정 http.force_exit를 참고하십시오.

인수

clean_ob

whether to destroy all previously started output handlers and their buffers

반환값

성공 시 TRUE를, 실패 시 FALSE를 반환합니다.

예제

Example #1 A HttpResponse::send() example

<?php
HttpResponse
::setCache(true);
HttpResponse::setContentType('application/pdf');
HttpResponse::setContentDisposition("$user.pdf"false);
HttpResponse::setFile('sheet.pdf');
HttpResponse::send();
?>

참고

add a note add a note

User Contributed Notes 2 notes

up
0
lymber
14 years ago
how to respond to a http request
Note that if you output data before sending the response then you will get a warning saying: Cannot modify header information - headers already sent. So do not echo any data in your responding script.
<?php
//process the request by fetching the info
$headers = http_get_request_headers();
$result = http_get_request_body();
//do stuff with the $headers and $result variables....
//then send your response
HttpResponse::status(200);
HttpResponse::setContentType('text/xml');
HttpResponse::setHeader('From', 'Lymber');
HttpResponse::setData('<?xml version="1.0"?><note>Thank you for posting your data! We love php!</note>');
HttpResponse::send();
?>
up
0
barnett dot [NOSPAM]thomas at gmail dot com
15 years ago
I was having a problem with the bytes appended to the output, using the given example.

<?php
...
HttpResponse::setFile('sheet.pdf');
HttpResponse::send();
?>

Content-Length mismatch: Response Header claimed x bytes, but server sent x+5 bytes.

Adding an exit statement solved this problem.
To Top