// Set error reporting level to E_ALL to report all errors and warnings
error_reporting(E_ALL);
This setting ensures that PHP captures and logs all errors and warnings.
// Write error message to a specified log file
error_log("Error: Something went wrong!", 3, "/path/to/logfile.log");
This code writes the error message to the log file located at /path/to/logfile.log.
class CustomSoapServer extends SoapServer {
public function __doRequest($request, $location, $action, $version, $one_way = 0) {
try {
// Specific service business logic
// ...
throw new SoapFault('Server', 'Something went wrong!');
} catch (SoapFault $fault) {
// Log error message or send alerts
error_log($fault->getMessage());
// Return a custom fault response
return $this->fault($fault->getCode(), $fault->getMessage());
}
}
}
// Instantiate the custom SOAP server
$server = new CustomSoapServer("wsdlFile.wsdl");
This approach allows capturing exceptions during service processing and logging them for easier troubleshooting.
function checkWebService($url) {
$timeout = 10; // Timeout in seconds
$handle = curl_init($url);
curl_setopt($handle, CURLOPT_RETURNTRANSFER, true);
curl_setopt($handle, CURLOPT_CONNECTTIMEOUT, $timeout);
$response = curl_exec($handle);
$httpCode = curl_getinfo($handle, CURLINFO_HTTP_CODE);
curl_close($handle);
}
// Periodic service status check
if (checkWebService("http://example.com/webservice")) {
echo "Web service is running fine.";
} else {
echo "Web service is down.";
}
This code determines service health based on the HTTP response code, enabling automated monitoring.