Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does it mean to run PHP in quiet mode?

Tags:

php

You can run PHP with the -q command line switch. The manual only say:

Quiet-mode. Suppress HTTP header output (CGI only).

What does that actually mean in practical terms?

like image 296
Kit Sunde Avatar asked Apr 25 '11 11:04

Kit Sunde


2 Answers

This only concerns the PHP interpreter built against the CGI SAPI. This version sends a few basic HTTP headers before any actual output:

X-Powered-By: PHP/5.3.3-1ubuntu9.3
Content-type: text/html

"(echo) What I actually wanted to have"

So basically the -q commandline flag prevents any header() from being written to stdout.

The purpose is to use the php-cgi binary in lieu of the php CLI variant for console scripts. Usually you see following shebang in such scripts to force php-cgi to behave like the -cli version:

#!/usr/bin/php-cgi -qC
like image 144
mario Avatar answered Oct 30 '22 20:10

mario


As you can see with -q key php suppresses to send headers (added some new lines in the output though to make it more readable):

zerkms@l12 ~ $ cat file.php
<?php

header('Location: http://stackoverflow.com');

echo 42;

zerkms@l12 ~ $ php file.php
Status: 302 Moved Temporarily
X-Powered-By: PHP/5.2.17
Location: http://stackoverflow.com
Content-type: text/html

42

zerkms@l12 ~ $ php -q file.php
42
like image 41
zerkms Avatar answered Oct 30 '22 20:10

zerkms