PHP exec() and shell_exec() functions cause hanging
08-10-2015, 02:35 PM
(This post was last modified: 08-11-2015, 07:32 AM by steve_nf.)
Hi guys,
I'm having a problem with the PHP functions exec() and shell_exec(). Nothing in the php after the exec will execute. Even a simple
causes it.
Things that could be the problem, and what I've tried:
I've also tried including 'sudo', like exec("sudo echo 'hello'"); , but it didn't make a difference.
The problem only occurs on my DigitalOcean server that's running Ubuntu 12.04 with Sentora. On my local copy of the website, which is ran on Windows 10, I don't have this problem.
Edit: I'm aware that it's not great to use exec() as it leaves the website vulnerable. The reason why I'm using it is because my website works like this: User uploads an image, and a program written in C++ (on the server) runs on the image, extracting information. The information is then stored in a database, and the image is deleted. So, I use exec() to get the C++ program to run on the image. Is there a smarter way to go about doing this?
Any help would be appreciated. Thank you for your time!
I'm having a problem with the PHP functions exec() and shell_exec(). Nothing in the php after the exec will execute. Even a simple
PHP Code:
exec("echo 'hello'");
causes it.
Things that could be the problem, and what I've tried:
- The apache user may not have sufficient permissions. Though as the root user I did run
sudo -H -u www-data bash -c 'echo "I am $USER, with uid $UID"'
- The exec functions may still be blocked somehow, even though I have already erased everything in the disable_functions entry in /etc/php5/apache2/php.ini, and restarted apache2:
I've also tried including 'sudo', like exec("sudo echo 'hello'"); , but it didn't make a difference.
The problem only occurs on my DigitalOcean server that's running Ubuntu 12.04 with Sentora. On my local copy of the website, which is ran on Windows 10, I don't have this problem.
Edit: I'm aware that it's not great to use exec() as it leaves the website vulnerable. The reason why I'm using it is because my website works like this: User uploads an image, and a program written in C++ (on the server) runs on the image, extracting information. The information is then stored in a database, and the image is deleted. So, I use exec() to get the C++ program to run on the image. Is there a smarter way to go about doing this?
Any help would be appreciated. Thank you for your time!