php - PHP 使用 header('Content-Type: audio/mpeg') 时使用 file_put_contents 复制日志条目;
问题描述
我正在使用 php 播放混合的 mp3 文件。我在加载页面时一直遇到问题,它执行我的日志记录功能两次。这会导致日志中出现重复条目。我简化了我的代码以在此处发布。
当我执行以下 php 文件时,它会在浏览器中完美播放“test.mp3”。我的 error_log 中没有错误。
<?php
header('Content-type: audio/mpeg');
header('X-Pad: avoid browser bug');
header('Cache-Control: no-cache');
print readfile("test.mp3");
$logentry = date("l jS \of F Y h:i:s A") . " Play Successful\n";
file_put_contents('play.log', $logentry, FILE_APPEND);
?>
在加载上述 php 一次后查看我的 play.log 文件,我得到以下信息:
Monday 24th of August 2020 03:57:10 AM Play Successful
Monday 24th of August 2020 03:57:10 AM Play Successful
重复条目。为了进一步隔离,我注释掉了“header('Content-type: audio/mpeg');” 行和网页按预期加载二进制 mp3 文件(一堆随机字符)。当我检查日志文件时,我看到它按应有的方式创建了一个条目。
为什么要使用“header('Content-type: audio/mpeg');”的任何想法 导致双浸?在 Chrome 和 Edge 中加载脚本时会发生这种情况。使用 Safari,我得到了酒水条目。IE 我得到一个应有的条目。
我怎样才能使这项工作在所有浏览器中可靠地工作以获得准确的日志?
解决方案
推荐阅读
- sql - 表的“三角关系”中的 SQL 查询
- java - 如何解决“找不到符号”的问题?
- c# - C# System.Text.Json JSON 值无法转换为类结构
- mysql - 我在 docker 上设置了 mysql 和 apache 超集并通过桥接网络连接,SQLAlchemy URI 是什么?
- firebase - 退出后无法登录 - Firebase Google Signin with Flutter
- django - DJANGO - 模型中的默认过滤器
- reactjs - Material UI:访问子节点
- 零件
- javascript - 在项目中包含 X 射线刮刀时出现 Npm 错误
- reactjs - React Typesscript 消费组件回调
- android - 无法关闭或点击 Admob 应用