<?php
// $data is assumed to contain the data to be signed
// fetch private key from file and ready it
$pkeyid = openssl_pkey_get_private("file://sign/key.pem");
// compute signature
openssl_sign($data, $signature, $pkeyid);
// free the key from memory
openssl_free_key($pkeyid);