tags:

views:

43

answers:

2

Is there any function in PHP that I can use to detect whether or not the exec function is available?

+2  A: 
<?php
function exec_enabled() {
  $disabled = explode(', ', ini_get('disable_functions'));
  return !in_array('exec', $disabled);
}
?>
UltimateBrent
A: 

You can search the ini setting disable_functions for the exec() function.

if( false !== strpos(ini_get("disable_functions"), "exec") ) {
 // exec() is disabled

Just for completeness, note that PHP Safe Mode puts some restrictions on the function too.

svens
Way too slow as I see :)
svens
This will return the wrong answer if a function like `shell_exec` has been placed in `disable_functions` but `exec` has not. Best to use explode or regex to make sure it matches a complete function name.
webbiedave
Whoops, that's correct.
svens