Command Line Usage Flashcards
Does the PHP CLI support GET, POST, or file uploads?
No.
How can you set whether a client disconnect should abort script execution?
ignore_user_abort()
Does the CLI SAPI change the current directory to the directory of the executed script?
No.
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.
- php –rf [[function]]
- php -rc [[class]]
- php -re [[extension]]
- php -ri [[extension]]
How can you set a custom value for any of the configuration values allowed in php.ini, from the command line?
php -d configuration_directive[=value]
How can you print out phpinfo() on the command line?
php -i
How can you check a file for syntax and fatal errors?
php -fl
How can you print out built-in modules?
php -m
How can you execute php code directly from the command line?
php -r ‘$foo = get_defined_constants(); var_dump($foo);’
Using single quotes prevents the shell’s variable substitution.
What does ‘php –ini’ do?
It displays configuration file names and scanned directories.
What does the first index of $argv contain?
The name of the script as called from the command line.
If PHP code is executed inline using the command line switch -r, what will the value of $argv[0] be?
A dash. The same is true if the code is executed via a pipe from STDIN.
What are the I/O stream constants defined for the CLI?
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.
What is the PHP interactive shell?
php -a
You are then able to type PHP code and have it executed directly.
Does the interactive shell store your command history?
Yes. It can be accessed using the up and down keys. It’s saved in the ~/.php_history file