PHP (Apache) silently converting HTTP 429 and others to 500

前端 未结 2 395
北荒
北荒 2020-12-31 12:18

I just discovered an oddity in PHP\'s header() method silently converting some of my statuses to 500. Since I had no luck in finding mention of this behavior in various web

相关标签:
2条回答
  • 2020-12-31 12:24

    It's perhaps your SAPI configuraiton. Last time I tested something similar, the conclusion looked like this:

    <?php
    header('HTTP/ 429 Too Many Requests', false, 429);
    echo "Too Many Requests\n";
    

    Which in your case works still well for me (Apache 2.2 / FCGI / Windows):

    >curl -i "http://local.example.com/header-test.php"
    HTTP/1.1 429 Too Many Requests
    Date: Thu, 18 Jul 2013 23:49:09 GMT
    Server: Apache/2.2.22 (Win32) mod_fcgid/2.3.6
    X-Powered-By: PHP/5.4.13
    Transfer-Encoding: chunked
    Content-Type: text/html
    
    Too Many Requests
    
    0 讨论(0)
  • 2020-12-31 12:44

    It's Apache, 99% sure, I can't find it direcly in it's docs, but I can infer it from the test below (Apache version 2.2.22)

    Add this in your config:

    ErrorDocument 429 Aaargh to heavy
    

    Restart:

    $ sudo /etc/init.d/apache2 restart
    Syntax error on line 6 of /etc/apache2/conf.d/localized-error-pages:
    Unsupported HTTP response code 429
    Action 'configtest' failed.
    The Apache error log may have more information.
       ...fail!
    

    429 also seems a recent addition in rfc6585, status: proposed, date: April 2012. One year old for HTTP RFCs is... just a baby in my experience. Add to that the process of getting it in Apache, and then in your package repositories... Well, you could try Apache 2.4...

    0 讨论(0)
提交回复
热议问题