Artisan服务发送带有嵌入式响应头的资产 [英] Artisan serve send assets with response headers embedded
问题描述
也许这很明显,但是我很难过,我刚刚发现我的本地PHP环境正在交付嵌入了响应头的静态文件.
Maybe this is something obvious but I'm having a hard time, I just found out that my local PHP environment is delivering static files with the response headers embedded.
这是Fedora 20上具有PHP 5.5.11的Laravel 4.1.26,已经测试了laravel serve
和php -S localhost:8000 server.php
,两者的结果相同.
This is Laravel 4.1.26 with PHP 5.5.11 on Fedora 20, already tested laravel serve
and php -S localhost:8000 server.php
, both with equal results.
我尝试使用Firefox,Opera和Chromium,看起来好像正在显示原始二进制响应:
I tried with Firefox, Opera and Chromium, it looks like is displaying the raw binary response:
这导致我所有的js文件出错.
This is causing errors on all my js files.
我尝试了curl
和wget -q -O -
的价值,并且响应正常,没有显示标题.看起来像PHP的内置服务器问题,我应该首先在哪里挖掘?
For what is worth I tried curl
and wget -q -O -
and the responses are ok, no headers displayed. This looks like PHP's built-in server issue, where should I dig first?
这不是PHP的事情,如果我踩到公用文件夹并使用php -S
启动服务器(忽略server.php
和laravel serve
)就可以了.
This is not a PHP thing, it has something to do with Laravel's emulation of mod_rewrite with the file "server.php", if I step on the public folder and launch the server with php -S
(ignoring server.php
and laravel serve
) then is all fine.
只是缩小了搜索范围,artisan serve
在具有相同PHP版本(5.5.11)的Debian 8 Jessie中可以正常运行,在Fedora环境中有所不同.
Just narrowed the search, artisan serve
runs ok in Debian 8 Jessie with the same PHP version (5.5.11), something is different in the Fedora environment.
推荐答案
只需更改:
if ($uri !== '/' && file_exists(__DIR__.'/public'.$uri)) {
return false;
}
到
if ($uri !== '/' && file_exists(__DIR__.'/public'.$uri)) {
ob_end_clean ();
return false;
}
它为我解决了
这篇关于Artisan服务发送带有嵌入式响应头的资产的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!