nginx - 如何将数据从 php-fpm 传递到 nginx 访问日志?

标签 nginx php

我试图通过在 nginx 中记录请求 URL 和 $request_time 来查找 PHP 应用程序中的瓶颈。不幸的是,$request_time包含网络延迟,我无法优化。我希望日志包含另一个具有纯页面生成时间的字段,因此我可以将其与 $request_time 进行比较。

我假设对于慢速连接,nginx 会快速获取 php-fpm 输出,然后等待客户端下载它。我可以测量 PHP 中的生成时间,但如何将其放入 nginx 访问日志中?

最佳答案

将您希望 nginx 通过 PHP 登录的数据放入 header 中。

header('RequestTime', 1234);

要求 nginx 将 header 的值记录到 nginx 配置文件中。

log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
              '$status $body_bytes_sent "$http_referer" '
              '"$http_user_agent" "$http_x_forwarded_for" $upstream_http_requesttime';

请注意,该值也将通过 header 发送到客户端,因此额外 header 中不应包含任何敏感性质的内容。

关于nginx - 如何将数据从 php-fpm 传递到 nginx 访问日志?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29251213/

相关文章:

xml - 包含以意外字符结束的 XML 书本的 HTTP 响应

nginx - 在Kubernetes的前端和后端之前配置Nginx

linux - Apache 如何访问 root 用户创建的 SSL 证书?

PHP 正则表达式定界符,/vs。 |与 {} ,有什么区别?

php - Reactphp进程状态统计(空闲、工作等)

ruby-on-rails - 请升级到 Ruby 1.9.3 或更新版本以继续

php - 通过 phpmailer 发送电子邮件(托管在 Google Apps 上的电子邮件地址)

php - Bootstrap Typeahead 不适用于动态输入

php - 地址栏中有 "#;"的 firefox

php - LAMP 服务器上的多个 php-fpm 版本