HttpResponse::send

(PECL pecl_http >= 0.10.0)

HttpResponse::sendSend response

Beschreibung

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-Einstellungen http.log.cache is set. INI-Einstellungen http.force_exit beschreibt, was "exits" bedeutet.

Parameter-Liste

clean_ob

whether to destroy all previously started output handlers and their buffers

Rückgabewerte

Gibt bei Erfolg TRUE zurück. Im Fehlerfall wird FALSE zurückgegeben.

Beispiele

Beispiel #1 A HttpResponse::send() example

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

Siehe auch

add a note add a note

User Contributed Notes 2 notes

up
1
lymber
4 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
6 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