MCQs Of Class 33:
PHP Configuration and Environment
Here are 100 multiple-choice questions (MCQs) based on PHP Configuration and Environment:
1-20: Basic
PHP Configuration
1. Which of
the following files is used to configure PHP settings?
o
A) php.ini
o
B) .htaccess
o
C) config.php
o
D) php.conf
o
Answer: A) php.ini
2. What does
the max_execution_time setting in php.ini control?
o
A) The time a script can run before it is stopped
o
B) The maximum memory a script can use
o
C) The maximum number of PHP scripts that can run
simultaneously
o
D) The number of times an error can occur
o
Answer: A) The time a script can run
before it is stopped
3. Which
directive in php.ini is used to enable or disable the display of errors
in PHP?
o
A) display_errors
o
B) error_reporting
o
C) log_errors
o
D) show_errors
o
Answer: A) display_errors
4. What is
the default value of display_errors in a production environment?
o
A) On
o
B) Off
o
C) Error
o
D) Log
o
Answer: B) Off
5. Which
directive controls the maximum file size for uploaded files in PHP?
o
A) file_size_limit
o
B) upload_max_filesize
o
C) post_max_size
o
D) max_file_size
o
Answer: B) upload_max_filesize
6. Which PHP
function is used to read environment variables?
o
A) getenv()
o
B) $_ENV()
o
C) get_config()
o
D) env_get()
o
Answer: A) getenv()
7. What does
the error_log directive in php.ini define?
o
A) The location of the error log file
o
B) The file where output should be written
o
C) The number of errors logged
o
D) The location of the PHP log
o
Answer: A) The location of the error log
file
8. Which
configuration directive in php.ini sets the maximum amount of
memory a script can consume?
o
A) memory_limit
o
B) max_memory_usage
o
C) memory_usage_limit
o
D) max_execution_memory
o
Answer: A) memory_limit
9. Which of
the following is the correct setting for max_execution_time to limit
the execution of scripts to 60 seconds?
o
A) max_execution_time = 60
o
B) max_execution_time = 60000
o
C) max_execution_time = 0
o
D) max_execution_time = 1
o
Answer: A) max_execution_time = 60
10.
Which PHP function can be used to modify the php.ini settings
at runtime?
o
A) ini_set()
o
B) config_set()
o
C) set_ini()
o
D) change_ini()
o
Answer: A) ini_set()
11.
What happens when error_reporting is set
to E_ALL & ~E_NOTICE?
o
A) It reports all errors except for notices
o
B) It only reports fatal errors
o
C) It reports only warnings
o
D) It reports all errors including notices
o
Answer: A) It reports all errors except
for notices
12.
What is the default value of max_input_time in PHP?
o
A) 60
o
B) 30
o
C) 120
o
D) 0
o
Answer: B) 30
13.
Which of the following directives should be set to
"On" to log errors in PHP?
o
A) log_errors
o
B) log_debug
o
C) error_log
o
D) display_errors
o
Answer: A) log_errors
14.
Which PHP function is used to stop script execution
after a certain time limit?
o
A) set_time_limit()
o
B) timeout_limit()
o
C) stop_time()
o
D) kill_time()
o
Answer: A) set_time_limit()
15.
What does max_input_vars control in PHP?
o
A) The maximum number of variables that can be
accepted from a form or URL
o
B) The maximum number of variables that can be
processed
o
C) The maximum number of database connections
o
D) The number of input fields in a form
o
Answer: A) The maximum number of
variables that can be accepted from a form or URL
16.
Which of the following is a correct use of the ini_set() function
in PHP?
o
A) ini_set('display_errors', 1)
o
B) set_ini('display_errors', 1)
o
C) configure_ini('display_errors', 1)
o
D) change_ini('display_errors', 1)
o
Answer: A) ini_set('display_errors', 1)
17.
What does the file_uploads directive in PHP do?
o
A) Enables or disables file uploads
o
B) Defines the maximum file size
o
C) Determines the file upload path
o
D) Specifies the types of files allowed for upload
o
Answer: A) Enables or disables file
uploads
18.
What PHP directive would you change to allow larger
file uploads?
o
A) upload_max_size
o
B) post_max_size
o
C) max_file_size
o
D) upload_limit_size
o
Answer: B) post_max_size
19.
In a production environment, what should display_errors be set
to in php.ini?
o
A) On
o
B) Off
o
C) Debug
o
D) Error
o
Answer: B) Off
20.
Which environment variable is commonly used to
define the application’s environment (development, production, etc.)?
o
A) ENVIRONMENT
o
B) APP_ENV
o
C) APP_MODE
o
D) CONFIG_ENV
o
Answer: B) APP_ENV
21-40: Advanced
PHP Configuration
21.
Which of the following configuration options is
used to limit the amount of time PHP will spend on parsing input data?
o
A) max_input_time
o
B) max_execution_time
o
C) input_timeout
o
D) execution_timeout
o
Answer: A) max_input_time
22.
What is the default value for memory_limit in PHP?
o
A) 128MB
o
B) 64MB
o
C) 256MB
o
D) 512MB
o
Answer: A) 128MB
23.
What happens if max_execution_time is set
to 0?
o
A) The script will run indefinitely
o
B) The script will stop after 60 seconds
o
C) The script will execute for 30 seconds
o
D) The script will execute for 120 seconds
o
Answer: A) The script will run
indefinitely
24.
Which of the following values of error_reporting will
report all errors including notices?
o
A) E_ALL
o
B) E_ERROR | E_WARNING
o
C) E_ALL & ~E_NOTICE
o
D) E_WARNING
o
Answer: A) E_ALL
25.
Which setting controls the maximum allowed POST
size in PHP?
o
A) upload_max_filesize
o
B) post_max_size
o
C) max_input_size
o
D) file_size_limit
o
Answer: B) post_max_size
26.
What does the auto_prepend_file
directive in php.ini do?
o
A) Automatically includes a file before the
execution of any PHP script
o
B) Automatically includes a file after the
execution of any PHP script
o
C) Prepares the PHP script before execution
o
D) Appends the specified file to the output buffer
o
Answer: A) Automatically includes a file
before the execution of any PHP script
27.
Which PHP directive sets the timezone for the PHP
script?
o
A) date.timezone
o
B) timezone
o
C) time_zone
o
D) time_zone_offset
o
Answer: A) date.timezone
28.
Which directive controls whether PHP logs errors to
a file or not?
o
A) log_errors
o
B) error_log
o
C) display_errors
o
D) log_errors_file
o
Answer: A) log_errors
29.
Which of the following is used to control the
timeout duration for accepting input data in PHP?
o
A) max_input_time
o
B) max_execution_time
o
C) input_timeout
o
D) post_max_size
o
Answer: A) max_input_time
30.
Which PHP function would you use to set the maximum
execution time for a specific script?
o
A) set_time_limit()
o
B) set_execution_time()
o
C) execution_time_limit()
o
D) set_max_execution()
o
Answer: A) set_time_limit()
31.
What does max_input_nesting_level in PHP
control?
o
A) The maximum depth of input variables
o
B) The maximum nesting level of loops in a script
o
C) The depth of the function call stack
o
D) The maximum number of form elements allowed
o
Answer: A) The maximum depth of input
variables
32.
What is the default value for post_max_size in PHP?
o
A) 8M
o
B) 2M
o
C) 32M
o
D) 10M
o
Answer: C) 32M
33.
Which function in PHP can be used to check the
current configuration value of upload_max_filesize?
o
A) phpinfo()
o
B) get_ini()
o
C) check_ini()
o
D) ini_get()
o
Answer: D) ini_get()
34.
What happens if upload_max_filesize is set
to a value smaller than post_max_size?
o
A) File uploads will be rejected
o
B) File uploads will succeed but be limited
o
C) Files larger than post_max_size will be automatically rejected
o
D) The script will handle the files internally
o
Answer: A) File uploads will be rejected
35.
Which of the following is a valid value for the date.timezone setting
in php.ini?
o
A) America/New_York
o
B) UTC
o
C) Europe/London
o
D) All of the above
o
Answer: D) All of the above
36.
In PHP, what is the purpose of the session.save_path
directive?
o
A) To define the location where session files are
stored
o
B) To define the location where cookie files are
stored
o
C) To save form input data
o
D) To set the session expiration time
o
Answer: A) To define the location where
session files are stored
37.
Which setting in php.ini is
responsible for limiting the maximum number of simultaneous file uploads in
PHP?
o
A) max_file_uploads
o
B) upload_max_filesize
o
C) file_uploads
o
D) max_uploads
o
Answer: A) max_file_uploads
38.
Which PHP setting should be adjusted if a PHP
script needs to handle large files for upload?
o
A) post_max_size
o
B) memory_limit
o
C) max_input_vars
o
D) max_file_uploads
o
Answer: A) post_max_size
39.
What is the purpose of the cgi.fix_pathinfo setting
in PHP?
o
A) It is used to resolve issues related to PHP
paths in CGI mode
o
B) It fixes paths in scripts
o
C) It determines the file upload path
o
D) It helps in script execution error handling
o
Answer: A) It is used to resolve issues
related to PHP paths in CGI mode
40.
In PHP, the short_open_tag directive is used to
enable/disable the use of which of the following?
o
A) Short PHP tags (<? ?>)
o
B) Shortened array syntax
o
C) Include files
o
D) PHP error handling
o
Answer: A) Short PHP tags (<? ?>)
41-60: PHP
Environment Setup
41.
Which command is used to check the current PHP
version from the command line?
o
A) phpinfo()
o
B) php -v
o
C) php -version
o
D) version_php()
o
Answer: B) php -v
42.
What should be done if the php.ini file is
not found?
o
A) It can be created manually
o
B) PHP will automatically create it
o
C) PHP will use default configuration settings
o
D) Both A and C
o
Answer: D) Both A and C
43.
What happens when you change the php.ini file
settings?
o
A) PHP automatically reloads
o
B) The changes take effect only after restarting
the web server
o
C) Changes are applied immediately
o
D) PHP needs to be recompiled
o
Answer: B) The changes take effect only
after restarting the web server
44.
Which of the following commands is used to display
the configuration settings of PHP?
o
A) php -c
o
B) phpinfo()
o
C) phpconfig()
o
D) config_php()
o
Answer: B) phpinfo()
45.
What is the purpose of the php_error.log file in
PHP?
o
A) It records PHP errors that occur during script
execution
o
B) It contains configuration errors
o
C) It logs the output of phpinfo()
o
D) It stores information about file uploads
o
Answer: A) It records PHP errors that
occur during script execution
46.
Which of the following is used to turn on or off
PHP error logging in php.ini?
o
A) log_errors = On/Off
o
B) error_log = On/Off
o
C) display_errors = On/Off
o
D) error_reporting = On/Off
o
Answer: A) log_errors = On/Off
47.
Where is the php.ini file located by default on a
Linux system?
o
A) /etc/php.ini
o
B) /usr/local/php.ini
o
C) /etc/php/7.x/apache2/php.ini
o
D) /php/php.ini
o
Answer: C) /etc/php/7.x/apache2/php.ini
48.
Which of the following is the main purpose of the display_errors
directive in PHP?
o
A) To display errors on the browser output
o
B) To log errors to a file
o
C) To enable warnings only
o
D) To display warnings but not errors
o
Answer: A) To display errors on the browser
output
49.
How can you view detailed information about the
current PHP environment and configuration?
o
A) Use phpinfo()
o
B) Use php_version()
o
C) Use php_config()
o
D) Use environment_info()
o
Answer: A) Use phpinfo()
50.
Which of the following is used to specify the
default file upload directory in PHP?
o
A) upload_directory
o
B) file_upload_path
o
C) upload_tmp_dir
o
D) upload_location
o
Answer: C) upload_tmp_dir
51-60: PHP
Optimization and Troubleshooting
51.
Which PHP setting controls whether user-defined
functions can be called using short tags (e.g., <?=) in a
script?
o
A) short_open_tag
o
B) enable_short_tags
o
C) use_php_tags
o
D) use_short_tags
o
Answer: A) short_open_tag
52.
What will happen if the max_execution_time
directive is set to a very low value?
o
A) PHP scripts may terminate prematurely
o
B) PHP will be more secure
o
C) The script will be optimized
o
D) PHP will work faster
o
Answer: A) PHP scripts may terminate
prematurely
53.
Which PHP directive controls whether PHP scripts
can be executed in the background without terminating the session?
o
A) allow_background_exec
o
B) background_exec
o
C) ignore_user_abort
o
D) session_timeout
o
Answer: C) ignore_user_abort
54.
What happens if the upload_max_filesize is set
too high?
o
A) It can cause slow uploads due to network
congestion
o
B) Large files may not be uploaded correctly
o
C) The server can crash if it lacks the necessary
resources
o
D) It improves upload speed
o
Answer: C) The server can crash if it
lacks the necessary resources
55.
What does the session.gc_maxlifetime
directive control?
o
A) The maximum time a session will remain active
before being garbage collected
o
B) The maximum time for the garbage collector to
run
o
C) The number of session files that can be created
o
D) The maximum time to store session variables
o
Answer: A) The maximum time a session
will remain active before being garbage collected
56.
Which of the following will help increase the
performance of a PHP-based web application?
o
A) Enabling opcode caching
o
B) Limiting error_reporting
o
C) Increasing memory limits
o
D) All of the above
o
Answer: D) All of the above
57.
What is the effect of setting session.auto_start = On in php.ini?
o
A) It automatically starts a session when a PHP
script is executed
o
B) It prevents sessions from being started manually
o
C) It disables the use of sessions
o
D) It logs all session activity
o
Answer: A) It automatically starts a
session when a PHP script is executed
58.
What does the error_reporting
directive control?
o
A) Which types of errors are reported by PHP
o
B) The maximum number of errors allowed
o
C) The destination for error logs
o
D) The level of logging for file uploads
o
Answer: A) Which types of errors are
reported by PHP
59.
What does the max_input_vars directive control in PHP?
o
A) The maximum number of input variables that PHP
will process
o
B) The number of files allowed to be uploaded
o
C) The maximum depth of arrays
o
D) The size of input forms
o
Answer: A) The maximum number of input
variables that PHP will process
60.
Which of the following commands can be used to check
the current status of PHP error logging?
o
A) phpinfo()
o
B) check_error_log()
o
C) error_log_status()
o
D) log_error_status()
o
Answer: A) phpinfo()
4o mini
You said:
give more
ChatGPT
said:
ChatGPT
Here are more MCQs on the topic
of PHP configuration and environment:
61-80: PHP
Configuration and Environment
61.
Which of the following is the correct setting for
allowing file uploads in PHP?
- A)
file_uploads = true
- B)
enable_file_uploads = On
- C)
allow_file_uploads = 1
- D)
file_uploads = On
- Answer: D)
file_uploads = On
62.
What does the max_input_vars directive control in PHP?
- A)
Maximum number of POST variables
- B)
Maximum size of uploaded files
- C)
Maximum number of form input elements
- D)
Maximum depth of input arrays
- Answer: C)
Maximum number of form input elements
63.
What is the purpose of the session.cookie_lifetime
directive in PHP?
- A)
It sets the expiration time of the session cookie in seconds
- B)
It defines how long sessions should last
- C)
It controls how long a user can stay logged in
- D)
It sets the path of the session cookie
- Answer: A)
It sets the expiration time of the session cookie in seconds
64.
Which PHP function retrieves the current
configuration settings from php.ini?
- A)
get_ini()
- B)
php_ini()
- C)
phpinfo()
- D)
ini_get()
- Answer: C)
phpinfo()
65.
In which file would you configure PHP error
settings on most Linux servers?
- A)
error_config.php
- B)
php_config.ini
- C)
php.ini
- D)
error_log.ini
- Answer: C)
php.ini
66.
Which of the following PHP directives is used to
specify the maximum size of a file that can be uploaded via HTTP?
- A)
file_max_size
- B)
max_upload_size
- C)
upload_max_filesize
- D)
max_file_size
- Answer: C)
upload_max_filesize
67.
Which of the following PHP directives controls
whether PHP can display errors to the browser?
- A)
error_reporting
- B)
log_errors
- C)
display_errors
- D)
show_errors
- Answer: C)
display_errors
68.
What is the effect of setting allow_url_fopen to Off in PHP?
- A)
PHP will block URL file access for functions like file_get_contents()
- B)
It prevents PHP scripts from including external files
- C)
It stops PHP from opening files with a URL wrapper
- D)
Both A and C
- Answer: D)
Both A and C
69.
Which PHP directive sets the maximum time a script
is allowed to run before being terminated?
- A)
max_execution_time
- B)
script_timeout
- C)
exec_timeout
- D)
max_script_duration
- Answer: A)
max_execution_time
70.
What does the session.save_path
directive in PHP specify?
- A)
The directory where session data is stored
- B)
The duration of session cookies
- C)
The session cookie domain
- D)
The maximum lifetime of session data
- Answer: A)
The directory where session data is stored
71.
What does the date.timezone directive in PHP control?
- A)
The time zone for PHP date/time functions
- B)
The default time zone for file operations
- C)
The time zone for session cookies
- D)
The system time zone
- Answer: A)
The time zone for PHP date/time functions
72.
Which PHP setting controls the maximum amount of
memory a script can allocate?
- A)
memory_limit
- B)
script_memory
- C)
max_memory
- D)
max_file_memory
- Answer: A)
memory_limit
73.
What happens if error_log is set
in php.ini?
- A)
PHP will output errors to a specific log file
- B)
PHP will output errors to the screen
- C)
PHP will ignore all errors
- D)
PHP will stop logging errors
- Answer: A)
PHP will output errors to a specific log file
74.
Which PHP directive specifies the maximum number of
files allowed to be uploaded at once?
- A)
max_file_uploads
- B)
upload_max_files
- C)
file_upload_limit
- D)
max_upload_files
- Answer: A)
max_file_uploads
75.
Which PHP setting controls whether variables will
be automatically registered in the global scope from incoming requests?
- A)
auto_globals
- B)
register_globals
- C)
global_vars
- D)
auto_register
- Answer: B)
register_globals
76.
Which setting in php.ini is
responsible for restricting the maximum number of variables allowed in a
request?
- A)
max_input_vars
- B)
input_max_vars
- C)
max_input
- D)
input_variables
- Answer: A)
max_input_vars
77.
What does the max_input_time directive in PHP control?
- A)
The maximum time allowed for parsing input data
- B)
The maximum time allowed for file uploads
- C)
The timeout duration for session handling
- D)
The maximum duration of input scripts
- Answer: A)
The maximum time allowed for parsing input data
78.
Which function in PHP can be used to set a value
for a configuration directive during runtime?
- A)
ini_set()
- B)
set_config()
- C)
php_config_set()
- D)
set_ini_value()
- Answer: A)
ini_set()
79.
In PHP, which setting affects the default file
permissions when a new file is created?
- A)
file_permission
- B)
default_file_mode
- C)
umask
- D)
file_mode
- Answer: C)
umask
80.
Which PHP directive controls whether the output of
a PHP script is cached?
- A)
output_buffering
- B)
cache_output
- C)
buffer_output
- D)
script_cache
- Answer: A)
output_buffering
81-100: Advanced
PHP Configuration
81.
Which of the following settings defines the default
character set used by PHP?
- A)
default_charset
- B)
charset
- C)
default_encoding
- D)
encoding_set
- Answer: A)
default_charset
82.
What does the session.use_cookies
directive control?
- A)
Whether session ID is passed via cookies
- B)
Whether session data is stored in cookies
- C)
Whether cookies are allowed in sessions
- D)
Whether cookies will be used to store user data
- Answer: A)
Whether session ID is passed via cookies
83.
Which directive in php.ini is used
to specify the default timezone for PHP functions?
- A)
timezone
- B)
default_timezone
- C)
date.timezone
- D)
time_zone
- Answer: C)
date.timezone
84.
Which PHP directive should be configured to handle
how long the server should wait for an HTTP request before it times out?
- A)
max_request_timeout
- B)
request_timeout
- C)
max_execution_time
- D)
http_timeout
- Answer: C)
max_execution_time
85.
What does the memory_limit directive do in PHP?
- A)
Sets the maximum amount of memory a script can consume
- B)
Sets the maximum file size for file uploads
- C)
Limits the number of script execution processes
- D)
Sets the size of data that can be sent through POST
- Answer: A)
Sets the maximum amount of memory a script can consume
86.
Which PHP directive affects the maximum execution
time of each PHP script?
- A)
script_timeout
- B)
max_execution_time
- C)
timeout_limit
- D)
max_time
- Answer: B)
max_execution_time
87.
What does the max_input_time directive control in PHP?
- A)
The maximum time allowed for parsing input data
- B)
The maximum time allowed for handling file uploads
- C)
The maximum time allowed for session variable loading
- D)
The timeout for executing PHP scripts
- Answer: A)
The maximum time allowed for parsing input data
88.
Which setting in php.ini helps
you manage file upload permissions?
- A)
upload_enable
- B)
file_upload_permission
- C)
file_uploads
- D)
max_file_permission
- Answer: C)
file_uploads
89.
Which of the following is used to specify whether PHP
should automatically display errors on the browser during development?
- A)
display_errors
- B)
show_errors
- C)
error_log
- D)
log_errors
- Answer: A)
display_errors
90.
Which of the following functions is used to
retrieve a configuration setting at runtime in PHP?
- A)
phpinfo()
- B)
ini_get()
- C)
get_php_setting()
- D)
get_ini_value()
- Answer: B)
ini_get()
91.
What is the purpose of the session.cookie_lifetime
directive in PHP?
- A)
Specifies how long the session cookie will persist
- B)
Specifies the path for the session cookie
- C)
Controls whether the session uses cookies
- D)
Sets the maximum session lifetime
- Answer: A)
Specifies how long the session cookie will persist
92.
Which PHP directive defines the length of the
session cookie?
- A)
session_cookie_duration
- B)
session.cookie_lifetime
- C)
cookie_timeout
- D)
session_timeout
- Answer: B)
session.cookie_lifetime
93.
What happens when the file_uploads
directive is set to Off?
- A)
File uploads are disabled
- B)
File uploads are restricted to a specific size
- C)
Only text files can be uploaded
- D)
Files are automatically compressed during upload
- Answer: A)
File uploads are disabled
94.
Which of the following will prevent PHP from
processing forms that exceed the maximum input size?
- A)
max_input_size
- B)
post_max_size
- C)
max_input_vars
- D)
max_file_size
- Answer: B)
post_max_size
95.
Which directive allows you to specify a time zone
for PHP?
- A)
time_zone
- B)
date.timezone
- C)
timezone
- D)
default_timezone
- Answer: B)
date.timezone
96.
Which of the following functions in PHP is used to
set configuration options at runtime?
- A)
ini_set()
- B)
set_config()
- C)
php_config()
- D)
change_ini()
- Answer: A)
ini_set()
97.
What will happen if you set session.auto_start to On in PHP?
- A)
The session will automatically be started on each script execution
- B)
It will prevent multiple sessions from being started
- C)
It will create a session only when a session variable is set
- D)
It will enable file upload in the session
- Answer: A)
The session will automatically be started on each script execution
98.
Which of the following settings controls whether
PHP should automatically register global variables from incoming requests?
- A)
register_globals
- B)
auto_globals
- C)
global_vars
- D)
auto_register
- Answer: A)
register_globals
99.
What is the purpose of max_input_time in PHP?
- A)
It specifies the maximum time to parse incoming request data
- B)
It limits the amount of data that can be parsed from incoming requests
- C)
It sets the maximum time for input validation in forms
- D)
It controls how long a file can be uploaded
- Answer: A)
It specifies the maximum time to parse incoming request data
100.
Which of the following options is true about the upload_max_filesize
directive in PHP?
- A)
It defines the size of files that can be uploaded using the POST
method
- B)
It sets the total size of all uploaded files combined
- C)
It limits the file size for all uploads
- D)
It sets the file size for text files only
- Answer: A)
It defines the size of files that can be uploaded using the POST
method
These MCQs cover a broad range of
concepts related to PHP configuration and environment management.