Command Line Flashcards

1
Q

How can the CLI SAPI be disabled?

A

By using the –disable-cli option when running ./configure.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

How can you determine whether you have CGI or CLI SAPI?

A

Type ‘php -v’ at the shell.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

How does the CLI SAPI differ from other SAPIs?

A
  • No headers are written to output, and there’s no switch to enable them.
  • It does not change the working directory to that of the script.
  • Plain text error messages.
  • Certain php.ini directives are overridden by the CLI SAPI because they do not make sense in shell environments.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What php.ini directives are overridden by the CLI SAPI?

A

html_errors - defaults to false, as these can be hard to read from the command line.

implicit_flush - output is displayed immediately, and not held in a buffer.

max_execution_time - set to unlimited for the shell.

register_argc_argv - defaults to true, so that scripts executed via the CLI SAPI always have access to argc (number of arguments passed to the application) and argv (array of the actual arguments).

output_buffering - FALSE

max_input_time - FALSE; the CLI does not support GET, POST, or file uploads.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Can the CLI SAPI overridden directives be altered in php.ini or a custom .ini file?

A

No. However, their values can be changed during runtime.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Does the CLI SAPI change the current directory to the directory of the executed script?

A

No.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

How can you display the list of PHP command line options?

A

php -h

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

How can you pass arguments to a script on the PHP command line?

A

The first argument must be –

Otherwise, PHP will interpret them as PHP options.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

How can you test for syntax AND fatal errors on the command line?

A

With the -f switch.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

On the command line, what options will not work with together with -l?

A

-r

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

How can you print built-in (and loaded) PHP and Zend modules?

A

php -m

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

How can you execute php directly on the command line?

A

With the -r switch.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

What’s problematic about using double quotes with the -r option to execute php directly on the command line?

A

sh/bash performs variable substitution when using double quotes. However, variables in single-quoted strings are not expanded by sh/bash.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

Is -r available in the CGI SAPI?

A

No.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

What is the -S flag for PHP?

A

It starts the built-in web server.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

What does php -z do?

A

Loads Zend extension.

17
Q

What does php –ini do?

A

Show configuration file names and scanned directories.

18
Q

What does php -rf do?

A

Show information about the given function or class method.

19
Q

What does php -rc do?

A

Show information about the given class.

20
Q

What are the three ways of supplying the CLIP SAPI with PHP code to be executed?

A
  1. Tell PHP to execute a file. php myscript.php or php -f myscript.php (the filename is not required to have a .php extension).
  2. Pass the PHP code to execute directly on the command line.
  3. Provide the PHP code to execute via standard input.

These cannot be combined.

21
Q

Can you use the beginning and ending php tags with the -r switch?

A

No. It will lead to a parse error.

22
Q

The arguments to a command line php script are available in the global array…

A

…$argv

23
Q

What does the first index (0) of $argv contain?

A

The name of the script as called from the command line.

24
Q

When is the value of $argv just a dash?

A

When the code is executed inline using the command line switch -r (the same is true if the code is executed via a pipe from STDIN).

25
Q

What do you do if you have to pass an argument beginning with a - to a command line php script?

A

Use the argument list separator: –

26
Q

Does the shebang line for unix PHP scripts cause problems on Windows?

A

No.

27
Q

What constants does the CLI SAPI define?

A

STDIN, STDOUT, and STDERR

28
Q

Are the CLI SAPI streams closed automatically?

A

Yes, when the PHP script ends.

29
Q

When are the CLI SAPI streams not available?

A

When reading the PHP script from stdin.

30
Q

How is the interactive shell enabled?

A

Using the -a option, as long as PHP is compiled with the –with-readline option.

31
Q

Where is the interactive shell history stored?

A

~/.php_history

32
Q

What are the cli.pager and cli.prompt settings in php.ini?

A

cli. pager - allows an external program such as less to act as the pager for the output, instead of being displayed directly on the screen.
cli. prompt - makes it possible to change the php > prompt.

33
Q

Can you set php.ini settings in the interactive shell using a shorthand notation?

A

Yes.

34
Q

Can you have PHP code executed in the shell prompt?

A

Yes; enclose the code in backticks.

35
Q

Which escape sequences are supported in the cli.prompt ini setting?

A

\e - used for adding colors
\v - the PHP version
\b - indicates which block PHP is in
> - indicates the prompt character

36
Q

What is not available if using PHP in interactive CLI mode?

A

Autoloading.

37
Q

With the built-in web server, from where are URI requests served?

A

From the current working directory where PHP was started, unless the -t option is used to specify an explicit document root. If the URI request does not specify a file, then either index.php or index.html in the given directory are returned. If neither exists, then a 404 response code is returned.

38
Q

How do you start the built-in PHP webserver?

A

php -S localhost:8000

39
Q

How can you make the built-in PHP webserver accessible on port 8000 to any interface?

A

php -S 0.0.0.0:8000