PHP Communication & Stakeholder Relations 4 — Questions and Answers
Question 1: Which PHP class is used to create a SOAP client for communicating with SOAP-based web services?
- SoapHandler
- SoapClient (Correct answer)
- WebServiceClient
- SoapRequest
Correct answer: SoapClient
SoapClient is PHP's built-in class for consuming SOAP web services, using a WSDL URL to discover available methods.
Question 2: In a PHP webhook receiver, what should you do immediately after verifying the webhook signature?
- Return HTTP 500 to pause delivery
- Process the payload synchronously before responding
- Return HTTP 200 quickly and queue the work asynchronously (Correct answer)
- Redirect the webhook sender to a callback URL
Correct answer: Return HTTP 200 quickly and queue the work asynchronously
Best practice is to return HTTP 200 immediately and process the payload asynchronously to prevent webhook timeouts.
Question 3: Which PHP function retrieves all HTTP request headers sent by the client?
- get_headers()
- apache_request_headers()
- getallheaders() (Correct answer)
- http_get_request_headers()
Correct answer: getallheaders()
getallheaders() retrieves all HTTP request headers as an associative array and is available in both Apache and PHP-FPM environments.
Question 4: What PHP function can send an email with HTML content by specifying MIME headers in the additional_headers parameter?
- mail() (Correct answer)
- sendmail()
- smtp_send()
- email()
Correct answer: mail()
PHP's built-in mail() function accepts additional headers like 'Content-Type: text/html' to send HTML-formatted emails.
Question 5: When building a REST API in PHP, which HTTP method is conventionally used to partially update an existing resource?
- POST
- PUT
- PATCH (Correct answer)
- UPDATE
Correct answer: PATCH
PATCH is the HTTP method used for partial updates to an existing resource, while PUT replaces the entire resource.
Question 6: In PHP, which output buffering function captures all output so headers can still be sent after content generation has started?
- ob_clean()
- ob_start() (Correct answer)
- ob_flush()
- ob_end_clean()
Correct answer: ob_start()
ob_start() begins output buffering, preventing content from being sent immediately and allowing headers to be set later.
Question 7: What is the purpose of the php://output stream in PHP?
- Reading raw POST input
- Writing directly to the response output buffer (Correct answer)
- Capturing error logs
- Streaming file uploads
Correct answer: Writing directly to the response output buffer
php://output is a write-only stream that allows writing directly to the output buffer, equivalent to using echo or print.
Which PHP class is used to create a SOAP client for communicating with SOAP-based web services?