0

I have a PHP script that calls a command-line utility via exec. It works fine on my (Xubuntu linux based) development machine, but not in my (CentOS linux based) testing environment on the production server.

In order to isolate the error, I have created the following test script:

<?php

  $command = "echo test";
  $output = array();
  exec($command, $output);

  foreach ($output as $line)
  {
    echo "new line: " . $line . "\n";
  }

  echo "done";
?>

When I run this via php test.php, I get the following output.

done

I.e. it seems that the exec command does not produce any output, as is the case in my real script.

What is the cause of this behavior or where to look for further information?

2
  • 1
    Is your testing machine a linux based machine? or windows? Commented Jun 12, 2013 at 16:11
  • Both the development environment and the testing/production machine are linux based. I updated the question to reflect that. Commented Jun 12, 2013 at 16:27

1 Answer 1

1

Many web servers will disable some PHP functions by default (some will also not allow you to modify those defaults). If you have a halfway decent webserver you should be able to edit the php.ini file. Look for a line which reads something like:

disable_functions =exec,passthru,shell_exec [ etc... ]

If you see that, remove exec fromt he list and restart your web service.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.