drqwbh2150 2012-08-25 16:23
浏览 177

来自其他用户的DBus

I'm trying to connect to DBus from a PHP program.

When I run the program from command-line, it works, but when it is run by the Apache webserver (running as user apache) it cannot connect to the bus.

I tried both calling qdbus with system and calling a Python script using python-dbus, but it doesn't work in either way. Also, I cannot manage to compile this PHP extension, but I don't think that it will solve my problem.

I think that the problem is that the DBus daemon that provides the session bus is running as my user (the system bus one is running as messagebus), but PHP runs as apache.

How can I do to connect to the other user's bus?

(This is not working for me.)

  • 写回答

1条回答 默认 最新

  • duanfen9983 2013-10-16 15:07
    关注

    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.
    评论

报告相同问题?

悬赏问题

  • ¥15 k8s部署jupyterlab,jupyterlab保存不了文件
  • ¥15 ubuntu虚拟机打包apk错误
  • ¥199 rust编程架构设计的方案 有偿
  • ¥15 回答4f系统的像差计算
  • ¥15 java如何提取出pdf里的文字?
  • ¥100 求三轴之间相互配合画圆以及直线的算法
  • ¥100 c语言,请帮蒟蒻写一个题的范例作参考
  • ¥15 名为“Product”的列已属于此 DataTable
  • ¥15 安卓adb backup备份应用数据失败
  • ¥15 eclipse运行项目时遇到的问题