响应的发送是通过index.php中的$response->send();实现的
vendor\symfony\http-foundation\Response.php
1 public function send() 2 { 3 $this->sendHeaders(); 4 $this->sendContent(); 5 6 if (function_exists('fastcgi_finish_request')) { 7 fastcgi_finish_request(); 8 } elseif (!\in_array(PHP_SAPI, array('cli', 'phpdbg'), true)) { 9 static::closeOutputBuffers(0, true); 10 } 11 12 return $this; 13 }
1 public function sendHeaders() 2 { 3 // headers have already been sent by the developer 4 if (headers_sent()) { 5 return $this; 6 } 7 8 // headers 9 foreach ($this->headers->allPreserveCase() as $name => $values) { 10 foreach ($values as $value) { 11 header($name.': '.$value, false, $this->statusCode); 12 } 13 } 14 15 // status 16 header(sprintf('HTTP/%s %s %s', $this->version, $this->statusCode, $this->statusText), true, $this->statusCode); 17 18 return $this; 19 }
1 2 3 4 5 6 | public function sendContent() { echo $this ->content; return $this ; } |
响应和发送分别是头信息发送和主题内容发送
头包括:状态行,首部字段和cookie的发送,状态行和首部字段是通过header()函数完成的,cookie发送是通过setcookie函数完成的
程序的终止
//程序的终止(index.php)
$kernel->terminate($request, $response);
1 2 3 4 5 6 | public function terminate( $request , $response ) { $this ->terminateMiddleware( $request , $response ); $this ->app->terminate(); } |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 | protected function terminateMiddleware( $request , $response ) { $middlewares = $this ->app->shouldSkipMiddleware() ? [] : array_merge ( $this ->gatherRouteMiddleware( $request ), $this ->middleware ); foreach ( $middlewares as $middleware ) { if (! is_string ( $middleware )) { continue ; } list( $name ) = $this ->parseMiddleware( $middleware ); $instance = $this ->app->make( $name ); if (method_exists( $instance , 'terminate' )) { $instance ->terminate( $request , $response ); } } } |
\vendor\laravel\framework\src\Illuminate\Foundation\Application.php
1 2 3 4 5 6 | public function terminate() { foreach ( $this ->terminatingCallbacks as $terminating ) { $this ->call( $terminating ); } } |
本文来自博客园,作者:孙龙-程序员,转载请注明原文链接:https://www.cnblogs.com/sunlong88/p/9365049.html
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· Linux系列:如何用heaptrack跟踪.NET程序的非托管内存泄露
· 开发者必知的日志记录最佳实践
· SQL Server 2025 AI相关能力初探
· Linux系列:如何用 C#调用 C方法造成内存泄露
· AI与.NET技术实操系列(二):开始使用ML.NET
· 被坑几百块钱后,我竟然真的恢复了删除的微信聊天记录!
· 没有Manus邀请码?试试免邀请码的MGX或者开源的OpenManus吧
· 【自荐】一款简洁、开源的在线白板工具 Drawnix
· 园子的第一款AI主题卫衣上架——"HELLO! HOW CAN I ASSIST YOU TODAY
· 无需6万激活码!GitHub神秘组织3小时极速复刻Manus,手把手教你使用OpenManus搭建本