Slim 3.3 输出中缺少字符

Slim 3.3 missing characters in output

我正试图在我的 Windows 7 系统上将 Slim 升级到 运行。 到目前为止,我已经用 Composer 安装了所有东西,但是当我 运行 一个非常简单的程序时,输出不是预期的。

下面是我的代码:

<?php
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);

use Slim\App;
use Slim\Http\Request;
use Slim\Http\Response;

require '../vendor/autoload.php';

$app = new App;

$app->get('/', function (Request $in, Response $out, $args) {
 return $out->write("xxxxx");
});

$app->run();

我期待输出 "xxxxx",但我得到 "x"。

这意味着我在某处丢失了 4 个字符。 运行 PHP 5.5.12 编码为UTF-8(不是BOM)

当我运行 "curl -v http://localhost:8080/"

我明白了

D:\wamp\www\slim_test\src\public>curl -v http://localhost:8080/
*   Trying 127.0.0.1...
* Connected to localhost (127.0.0.1) port 8080 (#0)
> GET / HTTP/1.1
> Host: localhost:8080
> User-Agent: curl/7.46.0
> Accept: */*
>
< HTTP/1.1 200 OK
< Host: localhost:8080
< Connection: close
< X-Powered-By: PHP/5.5.12
< Content-Type: text/html; charset=UTF-8
< Content-Length: 5
<

x* Closing connection 0

非常感谢你的帮助。

编辑 一旦我将这些代码行附加到文件末尾,响应就正确了。

$response = $app->run(true); //Silent mode, wont send the response
$response = $response->withoutHeader("Content-Length"); //Remove the Content-Length

$app->respond($response); //Now we send the response

我不明白为什么.....?

这个问题已经解决了,因为我发现了一个非常愚蠢的错误。

我在 <?php 标签前有 2 个空格。