-2

Take this example, does this load the echo if say for example php exec is enabled and I can run this command: /etc/init.d/mysql restart or would I need to set !== false to !== true?

$var = exec('/etc/init.d/mysql restart');

if ($var !== false) {
   echo "php exec is enabled";
}

Basically what I am trying to do is, restart mysql from php if this function is enabled on the server

$var = exec('/etc/init.d/mysql restart');

if ($var !== false) {
   exec('/etc/init.d/mysql restart');
   echo "php exec is enabled and restart mysql";
}
Jay
  • 73
  • 1
  • 2
  • 8

1 Answers1

2

How you are checking function it will gives you error

$var = exec(); // need to pass an argument

for check a function exist or not try

if(function_exists('exec')) {
    echo "php exec is enabled";
}

also according to updated you need to pass retrun argument to function to check returning values

exec('/etc/init.d/mysql restart', $output, $return);
// Return will return non-zero upon an error
if (!$return) {
   echo "php exec is enabled";
}

For more info :- http://in1.php.net/manual/en/function.exec.php

Rakesh Sharma
  • 13,680
  • 5
  • 37
  • 44