What are the best practices for handling SSL connections and certificates in PHP when interacting with HTTPS APIs or SOAP services?

When interacting with HTTPS APIs or SOAP services in PHP, it is important to handle SSL connections and certificates securely to ensure data integrity and confidentiality. One best practice is to verify the SSL certificate of the server you are connecting to, to prevent man-in-the-middle attacks. You can do this by setting the `verify_peer` and `verify_peer_name` options to true in your SSL context.

// Create a stream context with SSL options
$context = stream_context_create([
    'ssl' => [
        'verify_peer' => true,
        'verify_peer_name' => true
    ]
]);

// Make the HTTPS request with the created context
$response = file_get_contents('https://api.example.com', false, $context);

// Handle the response
// (e.g., process the data or handle any errors)