The Slim Framework support forum has moved to http://discourse.slimframework.com. This Tender forum is no longer maintained or monitored.

Response Header

Carsten's Avatar

Carsten

19 Dec, 2012 11:40 PM

Hello,

first, let me say that Slim is a powerful and easy to use framework that makes life really easy. Thank you.
I've just downloaded version 2.2.0 an it runs with PHP 5.4.9 and Hiawatha 8.6 very well.
But setting the status code in the HTTP response header using Slim

    $app = \Slim\Slim::getInstance();
    $app->halt(500, json_encode(array('status' => "ERROR")));
    echo "Some text.";

does not work. The returned status code is always 200.
Using PHPs native header('Status: 500 Error'); method returns the expected result to the client.
Thus, I think it's not a general problem related to PHP or Hiawatha.

I've noticed Michael's question, but unfortunately he didn't figured out, what the problem was in his php.ini file. I've tested both, output_buffering = "0" and output_buffering = "4096" in php.ini, but the result is the same (status code always 200).
I found a lot of threads concerning this issue, but didn't find a solution that works.

Thank you very much for your help on this topic.

Carsten

  1. Support Staff 1 Posted by Brian Nesbitt on 20 Dec, 2012 01:54 PM

    Brian Nesbitt's Avatar

    I am not too familiar with Hiawatha, but I know with nginx you can override the reverse proxy response status... any chance its doing that?

    BTW, are you running that code in a route or where?

  2. 2 Posted by Carsten on 20 Dec, 2012 03:04 PM

    Carsten's Avatar

    Running on an embedded computer. No virtual hosts, no reverse proxy etc..
    This is my hiawatha.conf file, most options are turned off:

    Binding {
        Port = 80
        Interface = 172.16.1.51
    }
    
    FastCGIServer {
        FastCGIId = php-fpm
        ConnectTo = 127.0.0.1:9000
        Extension = php
    }
    
    UrlToolkit {
        ToolkitID = slim
        Match ^/(css|files|images|js|slimstat)($|/) Return
        Match ^/(favicon.ico|robots.txt|sitemap.xml|test.php)$ Return
        Match .*\?(.*) Rewrite /index.php?$1
        Match .* Rewrite /index.php
    }
    
    Hostname = 172.16.1.51
    WebSiteRoot = /usr/local/var/www
    StartFile = index.html
    UseFastCGI = php-fpm
    UseToolkit = slim
    
    # no virtual hosts
    # no directories
    

    php.ini:

    cgi.fix.pathinfo= "0"
    cgi.rfc2616_headers = "1"
    expose_php = "1"
    display_errors = "1"
    output_buffering = "4096"
    ; output_buffering = "0"
    

    BTW: header('Status: 500 Error'); works, but not the Slim way.

  3. 3 Posted by ramzi on 26 Dec, 2012 04:05 PM

    ramzi's Avatar

    Hi,
    Have the same problem with the 2.2.0 version : 500 Error.
    My PHP is 5.3.10.
    Thank you for your help.

  4. 4 Posted by Stelling Carste... on 27 Dec, 2012 09:55 AM

    Stelling Carsten's Avatar

    Which type and version of web server do you use?

  5. 5 Posted by ramzi on 27 Dec, 2012 11:12 AM

    ramzi's Avatar

    Hi,
    Apache/2.2.22 (Ubuntu).
    PHP Version 5.3.10-1ubuntu3.4.

  6. 6 Posted by alex on 01 Sep, 2015 05:45 PM

    alex's Avatar

    Has anyone been able to figure this out? I have some users of my project who are having the same problem.

  7. 7 Posted by Stelling Carste... on 01 Sep, 2015 05:53 PM

    Stelling Carsten's Avatar

    Danke für Ihre Nachricht. Ich bin vom 17. August bis 8. September 2015 nicht im Haus und kann ihre Nachricht leider nicht bearbeiten. Ihre Nachricht wird nicht weitergeleitet. Wenden Sie sich bitte in dringenden Fällen an Herrn Götz Hasselberg mailto:[email blocked].

    Thank you very much for your message. I'm not in the office from 17th August to 8th September 2015. Your message will not be forwarded. In urgent cases, contact Mr. Götz Hasselberg mailto:[email blocked] please.

    Mit freundlichen Grüßen
    Best regards

    Carsten Stelling

    ______________________________________
    Carsten Stelling
    F&E Hardware / R&D Hardware

    GÖRLITZ Aktiengesellschaft | August-Thyssen-Straße 32 | D-56070 Koblenz
    T: +49-261-9285-336 | M: | F: +49-261-9285-190
    Mail to: [email blocked] | www.goerlitz.com

    Vorstand | Executive Board: Dipl.-Ing. Norbert Bartsch, Jörg Figge
    Vorsitzender des Aufsichtsrates | Chairman of the supervisory board: Norbert Wagner
    Registergericht | Court of registration: Amtsgericht Koblenz HRB 5346
    Sitz der Gesellschaft | Registered office: Koblenz
    Immer up-to-date mit unserem Newsletter! Hier geht's zur Anmeldung: www.goerlitz.com/newsletter<http://www.goerlitz.com/newsletter>
    Member of the IDS-Group

  8. 8 Posted by WilliamWero on 22 May, 2016 02:00 PM

    WilliamWero's Avatar

    Really informative post.Thanks Again. Really Great. Aujla

  9. 9 Posted by 1commcrazy on 27 Aug, 2016 03:51 AM

    1commcrazy's Avatar

    This is really great informative post. [CrazyBulk review](http://crazybulkonlinereviews.com/)

  10. 10 Posted by Stelling Carste... on 27 Aug, 2016 03:52 AM

    Stelling Carsten's Avatar

    Danke für Ihre Nachricht. Ich bin vom 5. bis 28. August 2016 nicht im Haus und kann ihre Nachricht leider nicht bearbeiten. Ihre Nachricht wird nicht weitergeleitet.

    Thank you very much for your message. I'm not in the office from 5th to 28th May 2016. Your message will not be forwarded.

    Mit freundlichen Grüßen
    Best Regards

    Carsten Stelling

    ______________________________________
     Carsten Stelling 
    F&E Hardware / R&D Hardware
     
    GÖRLITZ Aktiengesellschaft | August-Thyssen-Straße 32 | D-56070 Koblenz
    T: +49-261-9285-336 | M: | F: +49-261-9285-190
    Mail to: [email blocked] | www.goerlitz.com    
     
    Vorstand | Executive Board: Jörg Figge
    Vorsitzender des Aufsichtsrates | Chairman of the supervisory board: Norbert Wagner
    Registergericht | Court of registration: Amtsgericht Koblenz HRB 5346
    Sitz der Gesellschaft | Registered office: Koblenz
    Member of the IDS-Group
     

  11. 11 Posted by 1commreddet on 02 Sep, 2016 02:47 AM

    1commreddet's Avatar

    I am also getting same problem but there is no solution available on the internet. I tried searching about it on Google for couple of days but still no solution. visit here

  12. 12 Posted by ziwawisa on 24 Sep, 2016 05:54 AM

    ziwawisa's Avatar

    New topics will be introduced after this month.

  13. 13 Posted by yiqiremo on 26 Sep, 2016 03:03 AM

    yiqiremo's Avatar

    Xbox 360 Slim is more expensive than normal Xbox 360.
    http://bestbathmatehydropump.com/

  14. 14 Posted by sesulecu on 17 Oct, 2016 02:34 AM

    sesulecu's Avatar

    Please use heading in your articles.
    http://www.reviewprotocol.com/tao-of-badass/

  15. 15 Posted by gurudoro on 18 Oct, 2016 01:43 AM

    gurudoro's Avatar

    I am trying to load this video but buffering is not working.
    http://rickydiabetesdestroyed.com/teds-woodworking

  16. 16 Posted by zoyekucu on 19 Oct, 2016 01:05 AM

    zoyekucu's Avatar

    Getting 404 Error in the heading again and again.

  17. 17 Posted by zax on 24 Nov, 2016 03:39 AM

    zax's Avatar

    I keep on getting error again and again. How To Get Bigger Penis Fast

  18. 18 Posted by vibu on 30 Nov, 2016 02:41 AM

    vibu's Avatar

    This response header problem is getting bigger and bigger.
    read this page

Reply to this discussion

Internal reply

Formatting help / Preview (switch to plain text) No formatting (switch to Markdown)

Attaching KB article:

»

Attached Files

You can attach files up to 10MB

If you don't have an account yet, we need to confirm you're human and not a machine trying to post spam.

Keyboard shortcuts

Generic

? Show this help
ESC Blurs the current field

Comment Form

r Focus the comment reply box
^ + ↩ Submit the comment

You can use Command ⌘ instead of Control ^ on Mac