开发者

exec command works in terminal not with PHP

开发者 https://www.devze.com 2023-02-13 23:03 出处:网络
I\'m writing a class who let me access to recutils through PHP. I have a \'database\' file called books.rec in ../database/ and a script who runs my Recutils.php class.

I'm writing a class who let me access to recutils through PHP.

I have a 'database' file called books.rec in ../database/ and a script who runs my Recutils.php class.

My class simply launch system application with correct parameters.

But When I try to use recins with PHP's exec function, the command doesn't work will it work in command line.

This is the command that is executed by my script :

recins -f Title -v "Moi" -f Author -v "Moche" -f Location -v "loaned" -t Books ../database/books.rec

With PHP : Nothing, the record is not inserted (no error message at all too).

In terminal : OK, the command is well done and my record i开发者_开发问答s inserted.

I also have a method to do a select operation using recsel and it works very well, will it use exactly the same file (and runs from exec too).

So, could someone explain me why the command don't work will another with the same file work ?

Thanks

PS : Further informations : http://www.gnu.org/software/recutils/


I would double check that you are running the command as the same user from the command line and your php script. That may be the problem. exec('whoami')

You said you had a script that starts your php script it should be the same user as that.

You might also want to running a simpler exec command to see if that will work first.

Other things to try:

  1. Try checking stderr output exec('ls /tmp 2>&1', $out); This will redirect standard error to standard out so you get both.
  2. Try using php's shell_exec() which will invoke a shell just like when you are running from the command line(eg. bash). shell_exec('ls /tmp 2>&1 >> /tmp/log') should even put all output into a log file.
  3. I don't think this will help you but it is something to try if all else fails, set it as a background process and see if it completes. exec('nohup php process.php > process.out 2> process.err < /dev/null &'). The & will set the command to run in the background and let the script continue.

Good Luck


Is recins command accessible for PHP ? Also is path to books.rec correct ? Try with absolute path.

0

精彩评论

暂无评论...
验证码 换一张
取 消