3

我正在尝试从 PHP 程序连接到 DBus。

当我从命令行运行程序时,它可以工作,但是当它由 Apache 网络服务器(以用户身份运行apache)运行时,它无法连接到总线。

我尝试使用 python-dbus 调用qdbussystem调用 Python 脚本,但无论哪种方式都不起作用。另外,我无法编译这个 PHP 扩展,但我认为它不会解决我的问题。

我认为问题在于提供会话总线的 DBus 守护程序以我的用户身份运行(系统总线一个messagebusapache.

如何连接到其他用户的总线?

对我不起作用。)

4

1 回答 1

0

First of all, do you have a dbus method you are trying to call? Dbus is merely the transportation layer, you need a program that hosts a dbus method and a program that calls a dbus method. I'll assume you have a dbus method you want to call from your php program.

How is apache trying to call your dbus method? If you are using a system() method or similar from php to call qdbus, that will fail. PHP is run by apache, apache does not have an autologin dbus process like your user does and no X11 access. This means in order for your apache to have dbus, you have to use:

eval 'dbus-launch --auto-syntax' [command]

when using PHP's system(). That is not optimal though.

Some solutions are:

  1. Run apache as your user.
  2. Run dbus on the system bus and expose the methods and allow apache to call them from the dbus configuration file. This requires root access, which can complicate matters.
  3. Research if exposing a session dbus method to other users works. Optimally there should be a dbus-php library you can use. I'm pretty sure as long as apache can call dbus methods, having an xml file in the dbus config folder exposing it should work.
于 2013-10-16T15:07:20.870 回答