Command Line Usage Flashcards

1
Q

Does the PHP CLI support GET, POST, or file uploads?

A

No.

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

How can you set whether a client disconnect should abort script execution?

A

ignore_user_abort()

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
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
4
Q

How can you display the following on the command line:

  • Information about a function.
  • Information about a class.
  • Information about an extension.
  • Configuration for an extension.
A
  • php –rf [[function]]
  • php -rc [[class]]
  • php -re [[extension]]
  • php -ri [[extension]]
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

How can you set a custom value for any of the configuration values allowed in php.ini, from the command line?

A

php -d configuration_directive[=value]

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

How can you print out phpinfo() on the command line?

A

php -i

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

How can you check a file for syntax and fatal errors?

A

php -fl

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

How can you print out built-in modules?

A

php -m

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

How can you execute php code directly from the command line?

A

php -r ‘$foo = get_defined_constants(); var_dump($foo);’

Using single quotes prevents the shell’s variable substitution.

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

What does ‘php –ini’ do?

A

It displays configuration file names and scanned directories.

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

What does the first index of $argv contain?

A

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

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

If PHP code is executed inline using the command line switch -r, what will the value of $argv[0] be?

A

A dash. The same is true if the code is executed via a pipe from STDIN.

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

What are the I/O stream constants defined for the CLI?

A

STDIN, STDOUT, and STDERR.

Thus, you don’t have to open streams for the above; they can just be used as constants:

php -r ‘fwrite(STDERR, “stderr\n”);’

You do not need to explicitly close these streams, as they are closed automatically by PHP when your script ends.

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

What is the PHP interactive shell?

A

php -a

You are then able to type PHP code and have it executed directly.

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

Does the interactive shell store your command history?

A

Yes. It can be accessed using the up and down keys. It’s saved in the ~/.php_history file

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

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

A

The current working directory where PHP was started, unless the -t option is used to specify an explicit document root.

17
Q

What happens when a PHP file is given on the command line when the built-in web server is started?

A

It’s treated as a “router” script. The script is run at the start of each HTTP request.

18
Q

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

A

php -S 0.0.0.0:8000