Page 1 of 1
exec doesn't work when called from standalone app
Posted: Fri May 29, 2009 8:59 am
by webfaqtory
Hi
exec (or popen etc) doesn't work when called from a standalone (commandline) PHP app but does if called from a browser (running under the web server) eg.
outputs nothing (even if su) if called from commandline eg php myapp.php. But it works as expected if called from a browser http;//myserver.com/myapp.php.
OS is Solaris 10. Is this a permissions problem? Can't see how if I'm su.
Thanks
Re: exec doesn't work when called from standalone app
Posted: Fri May 29, 2009 1:20 pm
by jayshields
Probably permissions based yeah.
One thing, why would you want to call a PHP script that calls exec() through a command-line prompt?
Re: exec doesn't work when called from standalone app
Posted: Fri May 29, 2009 6:07 pm
by webfaqtory
Its a twitter service that can take 10 minutes get the latest tweets, DMs, local news, weather etc. Its a an async call so the main server continues running whilst gathering the above data eg 'php getAsyncdata.php > /dev/null &'
Re: exec doesn't work when called from standalone app
Posted: Sat May 30, 2009 1:12 am
by VladSun
Try
Code: Select all
<php
exec('ls 2>&1', $output);
print_r($output);
?>
and see what error messages you have.
Also, while
'php getAsyncdata.php > /dev/null &' is OK, I think you will find
pcntl_fork() interesting

Re: exec doesn't work when called from standalone app
Posted: Sat May 30, 2009 8:18 am
by webfaqtory
Hi VladSun
Thanks for your help.
Still the same, no output (other than the empty Array()). Called from a browser, of course, gives the full listing
Re: exec doesn't work when called from standalone app
Posted: Sat May 30, 2009 8:44 am
by VladSun
What about
Code: Select all
exec('ls / 2>&1', $output);
print_r($output);
echo `ls / 2>&1`;
echo shell_exec('ls / 2>&1');
Re: exec doesn't work when called from standalone app
Posted: Sat May 30, 2009 1:49 pm
by webfaqtory
Hi VladSun
No joy, nothing is outputed for any command
Re: exec doesn't work when called from standalone app
Posted: Sat May 30, 2009 2:29 pm
by VladSun
Do you run it with:
Code: Select all
php getAsyncdata.php > /dev/null &
?
If so, try to run it like this:
Re: exec doesn't work when called from standalone app
Posted: Sat May 30, 2009 2:31 pm
by webfaqtory
2nd option 'php getAsyncData.php'