lost and found ( for me ? )

PHP5.3 : configure HTTP response code you would like to send

small tips.

# tail -1 /etc/lsb-release ;uname -ri
DISTRIB_DESCRIPTION="Ubuntu 12.04.3 LTS"
3.2.0-54-virtual x86_64

# apt-get install apache2 php5 libapache2-mod-php5
# a2enmod php5
# service apache2 restart

# dpkg -l php5 | tail -1
ii  php5                            5.3.10-1ubuntu3.8                 server-side, HTML-embedded scripting language (metapackage)

In case of PHP5.3, you can configure HTTP response code like this:
# cat /var/www/a.php
<?php
header('X-PHP-Response-Code: 503', true, 503);
sleep(1);
echo date('h:i:s') . "\n";

?>

# wget http://127.0.0.1/a.php -O -
--2013-10-08 04:17:36--  http://127.0.0.1/a.php
Connecting to 127.0.0.1:80... connected.
HTTP request sent, awaiting response... 503 Service Temporarily Unavailable

In case of PHP5.4 or later, you can configure like this:
http_response_code(404);

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.