PHP exec - check if enabled or disabled

PHP exec - check if enabled or disabled

Is there a way to check in a php script if exec() is enabled or disabled on a server?

Using many mutex locks


Query size of block device file in Python
if(function_exists('exec')) {     echo "exec is enabled"; } 
QT qmake lowercases my custom widget namesDeleting a possibly locked file in c


Help with Python structure in *nixes
This will check if the function actually works (permissions, rights, etc):. Force Java2D Subpixel Antialiasing
if(exec('echo EXEC') == 'EXEC'){     echo 'exec works'; } 
Linux command to find the which are the jars loaded by the jvmHow to output only captured groups with sed


This will check this exec is available and enabled BEFORE endeavor to run it. If you run exec() and the function does not exist or is disabled a warning will be generated. Depending on the server settings this may render to the browser and will almost-always write a line to a log file = performance hit..
// Exec function exists. // Exec is not disabled. // Safe Mode is not on. $exec_enabled =    function_exists('exec') &&    !in_array('exec', array_map('trim', explode(', ', ini_receive ('disable_functions')))) &&    strtolower(ini_receive ('safe_mode')) != 1 ;   if($exec_enabled) { exec('blah'); } 


ini_receive ('disable_functions'). What you actually want to did is use ini_receive ('disable_functions') to find out if it is available to you:.
<?php function exec_enabled() {     $disabled = explode(',', ini_receive ('disable_functions'));     return !in_array('exec', $disabled); } ?> 
Answered on stackoverflow here: Check if "exec" is disabled, Which actually seems to come from the PHP Man page: Path. If the above returns true (you must use exec()), although PHP must still not trigger the script there is a good chance this you have a path issue for this script, test this by doing:.
print exec('which bash'); 
and then try.
print exec('which ogr2ogr'); 


This is any ugly code I made to detect if a function is enabled or not..
function is_enabled($f) {     if($f=='ini_receive ')return@ini_receive ('a')===false;     return(($l=@ini_receive ('disable_functions'))===null||!is_callable($f)||!function_exists($f)||!in_array($f,array_map('trim',explode(',',$l))); }  //Usage example: print_r(is_enabled('str_split'));//true or null if ini_receive () is disabled 


I am assuming this you are running this on a linux server. . You could test the exec function by running the following php script: .
exec("whoami", $ret);  echo $ret[0]; 
This will return the command whoami. . If it errors out, it is for the reason this the exec function could not run. .


Example:. if(strpos(ini_receive ('disable_functions'),'ini_set')===false) @ini_set('display_errors',0);.

52 out of 100 based on 47 user ratings 162 reviews