Web Programming Website And Web Server Programming 5 — Questions and Answers
Question 1: What is the purpose of environment variables in web server deployments?
- Store configuration values like API keys outside of source code (Correct answer)
- Speed up server response times
- Define CSS variables for dynamic theming
- Configure browser caching rules
Correct answer: Store configuration values like API keys outside of source code
Environment variables keep sensitive configuration (database URLs, secret keys) out of version control and allow different values per environment (dev/staging/prod).
Question 2: In HTTP/2, what is multiplexing?
- Sending multiple requests and responses simultaneously over a single TCP connection (Correct answer)
- Encrypting multiple streams with different keys
- Splitting a large file into chunks for parallel download
- Routing requests to multiple backend servers
Correct answer: Sending multiple requests and responses simultaneously over a single TCP connection
HTTP/2 multiplexing eliminates HTTP/1.1's head-of-line blocking by allowing concurrent streams over one connection.
Question 3: Which PHP function is used to redirect the user to another URL from server-side code?
- header('Location: ...') (Correct answer)
- redirect('...')
- move_to('...')
- Response::redirect('...')
Correct answer: header('Location: ...')
header('Location: URL') sends a redirect HTTP header; you typically follow it with exit() to stop further script execution.
Question 4: What is the main advantage of using a Content Delivery Network (CDN) for static web assets?
- Serves assets from edge servers geographically close to the user, reducing latency (Correct answer)
- Encrypts all asset files at rest on the origin server
- Automatically rewrites HTML to fix broken links
- Converts images to WebP format on the fly
Correct answer: Serves assets from edge servers geographically close to the user, reducing latency
CDNs cache and serve static content from globally distributed edge nodes, reducing round-trip time for users far from the origin server.
Question 5: In Node.js, what does the `process.env` object contain?
- The current process's environment variables (Correct answer)
- Installed npm package versions
- Active HTTP connections
- The Node.js runtime configuration file
Correct answer: The current process's environment variables
process.env provides access to the operating system environment variables set before or during the Node.js process startup.
Question 6: Which web server configuration technique maps incoming URL patterns to different backend applications or directories?
- URL rewriting / routing rules (Correct answer)
- MIME type configuration
- Gzip compression settings
- Connection timeout tuning
Correct answer: URL rewriting / routing rules
URL rewriting (e.g., mod_rewrite in Apache, rewrite rules in Nginx) allows flexible mapping of clean URLs to actual file paths or backend handlers.
Question 7: What does 'stateless' mean in the context of HTTP and RESTful web services?
- Each request must contain all information needed to process it; the server stores no session state between requests (Correct answer)
- The server never writes data to disk
- Responses are never cached by the client
- The server resets after every 100 requests
Correct answer: Each request must contain all information needed to process it; the server stores no session state between requests
Statelessness means the server treats each request independently, improving scalability since any server instance can handle any request.
What is the purpose of environment variables in web server deployments?