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. Смотрите INI-опцию http.force_exit для пояснения термина "выходит".

Список параметров

clean_ob

whether to destroy all previously started output handlers and their buffers

Возвращаемые значения

Возвращает TRUE в случае успешного завершения или FALSE в случае возникновения ошибки.

Примеры

Пример #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