I would like to know the simplest and fastest PHP code line to check if mcrypt extension is available/installed.
There is a function that encrypts a string and first it requires to check if mcrypt is usable. If not, it will execute an alternative encrypt solution available on the system.
Thanks!
Determine if the mcrypt extension is loaded in any of the following ways: Set up a phpinfo. php file in the web server's root directory and examine the output in a web browser. Run the following command: $ php -r "phpinfo();" | grep mcrypt.
The mcrypt PHP module provides an interface to the mcrypt library and supports encryption. The cPanel-provided EasyApache 4 profiles include the mcrypt PHP module by default.
ext/mcrypt ¶ The mcrypt extension has been abandonware for nearly a decade now, and was also fairly complex to use. It has therefore been deprecated in favour of OpenSSL, where it will be removed from the core and into PECL in PHP 7.2.
You can use function_exists
to check if one of the mcrypt functions exists.
if(function_exists('mcrypt_encrypt')) {
echo "mcrypt is loaded!";
} else {
echo "mcrypt isn't loaded!";
}
Edit 30.07.2016:
Since my answer still gets a few upvotes from time to time, I benchmarked the performance of mine and Cristi Draghici's answers. The conclusion is, that function_exists
is a bit faster than extension_loaded
. https://3v4l.org/So4Ep
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With