DreamHost Web Hosting
Discussion Forum


Forums
   >> General Troubleshooting
*Threaded Mode

Subject PHP and exec()  
Posted byNou (DH New User )
Posted on06/03/06 05:31 PM



For some reason I can't seem to get exec() to execute php scripts in the background.

For example I have a file called test.php that reads contains the line:

exec("/usr/local/php5/bin/php proc.php >/dev/null &");

When I run this php script from the shell ($:php test.php) it works fine and calls proc.php but if I call this same script from the web (http://www.somesite.com/test.php) it dosn't work right. It executes PHP but when I have the output sent to a log file (>log.txt instead of /dev/null) it says php found no input file!

Can anyone help me out with this? I have PHP-CGI running, its not an issue of exec being denied permission. It works calling other programs with arguments (ie: exec("ping -c 10 www.google.com >log.txt &") will run ping in the background and send its output to log.txt when called via HTTP).

Thanks in advance!



Subject Re: PHP and exec() new [re: Nou]  
Posted bysdayman (DH Enthusiast)
Posted on06/03/06 07:13 PM



exec() is disabled in apache's mod_php for security reasons. Your only option is to compile and install your own PHP.


-Scott


Subject Re: PHP and exec() new [re: sdayman]  
Posted byNou (DH New User )
Posted on06/03/06 07:24 PM



Its not disabled though in php-cgi which is the default and what this enviroment is... I said I can call it and it runs things like ping or even shell scripts fine, but for some reason it wont run php scripts, it will start php but for some reason php wont see the script passed to it. It wont even run php scripts called inside shell scripts... but it will run the shell script itself... its very odd.



Subject Re: PHP and exec() new [re: sdayman]  
Posted bysilkrooster (DH Enthusiast)
Posted on06/03/06 07:25 PM



Very odd, it worked back in February. So the only way to get ImageMagick to work is to install your own version of php?
Silk



Subject Re: PHP and exec() new [re: Nou]  
Posted bysdayman (DH Enthusiast)
Posted on06/03/06 07:59 PM



Oops, I'm a bit backwards, new setups don't even use mod_php, so that's not it. I wonder if it's an issue of PHP4 vs PHP5. Is your site set for PHP4?

-Scott


Subject Re: PHP and exec() new [re: sdayman]  
Posted byNou (DH New User )
Posted on06/03/06 08:40 PM



It's ok :P I'm running 5 on there, I'll try with 4 but I don't think thats the issue, as I have run it via command line using 4 and 5 and it works under both on command line...



Subject Re: PHP and exec() new [re: Nou]  
Posted byNou (DH New User )
Posted on06/03/06 09:07 PM



Uh lol well I changed it to PHP4, tried to run it again via http and it spawned like hundreds of processes... now I can't ssh in... lol really odd seeing that it didnt do that under PHP5... or maybe it was a fluke. Who knows...

Argh...



Subject Re: PHP and exec() new [re: Nou]  
Posted bysdayman (DH Enthusiast)
Posted on06/03/06 09:46 PM



I guess we learned something new today. I don't know what, though. Good luck getting it sorted out. It'll be interesting to hear what the problem is.

-Scott


Subject Re: PHP and exec() new [re: sdayman]  
Posted byNou (DH New User )
Posted on06/03/06 09:49 PM



Yea... it wasnt a fluke, PHP4 breaks exec() on gobstopper at least when you call it via CGI... I contacted tech and they either caught it before it crashed the server again or it figured itself out.... but uh yea, I don't think I will be trying that with PHP4 again!



Subject Re: PHP and exec() new [re: Nou]  
Posted byNou (DH New User )
Posted on06/03/06 10:20 PM



OK PHP seems to be the issue, as I can call perl scripts via exec() in PHP... but not PHP scripts via http...



Subject Re: PHP and exec() new [re: Nou]  
Posted bysilkrooster (DH Enthusiast)
Posted on06/03/06 10:24 PM



Man I feel like an idiot. User error. I had two copies of my script and forgot about it. So exec is working with ver 4 and cgi.
Silk



Subject Re: PHP and exec() new [re: Nou]  
Posted byNou (DH New User )
Posted on06/03/06 11:58 PM



Anyone have any idea why it would return 404 not found via exec() when you call it via the website, but not when you call it from the command line???



Subject Re: PHP and exec() new [re: Nou]  
Posted bydtra (DH New User )
Posted on12/07/07 07:55 PM



sorry to bring up an old issue, but has anyone found a solution to this?
i'm running php 5.2.5 as fast cgi and am having this same problem
not being able to execute a php script using exec() from the web, and it working perfectly fine from the command line

another thing i noticed, is that the exec-ed script spawns several times with different pids

dave

Edited by dtra on 12/07/07 09:33 PM (server time).



Subject Re: PHP and exec() new [re: dtra]  
Posted bydtra (DH New User )
Posted on12/08/07 09:43 PM



coolies, i found the answer, should've been using the cli php binary, and not the cgi binary




*Threaded Mode
Jump to