I'm trying to get Slim to run on my Windows 7 system. So far I've gotten everything installed with Composer but when I run a very simple program, the output is not as intended.
Below is my code:
<?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();
I am expecting output "xxxxx", instead i get "x".
This means I loose 4 characters somewhere. Running PHP 5.5.12 The encoding is UTF-8 (not BOM)
When i run "curl -v http://localhost:8080/"
I get
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
I'd appreciate your help.
EDIT Once i append these lines of code to the end of the file, the response is correct.
$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
I cannot figure out why.....?
This issue has been solved as I found a very stupid mistake.
I had 2 blank spaces before the <?php
tag.