What are the potential pitfalls of storing resources in PHP, especially when working with OpenSSL keys?

Storing resources in PHP can lead to potential memory leaks and security vulnerabilities, especially when working with sensitive data like OpenSSL keys. To avoid these pitfalls, it's recommended to serialize the resources before storing them and unserialize them when needed.

// Serialize the resource before storing
$serialized_key = serialize($openssl_key);

// Store the serialized key in a file or database

// When needed, unserialize the key
$openssl_key = unserialize($serialized_key);