简体   繁体   中英

xdotool refresh Browser with php or shell

have a RPI in Kioskmode running.

I wrote a php script that display a Scoreboard for Tabletennis, the points count up when press pushbuttons which are connected to a D1 Mini which is connected over wlan.

Now i need to refresh the Browserwindow to display the actual score from the database.

i found xdotool but i cant get it to work with shell_exec() in the php script.

When i use this command DISPLAY=:0.0 xdotool key F5 in commandline the browser refresh work, but when i try to du this out of a php script i cant get it to work.

Can someone help me get this running?

I tryed various versions:

  1. $cmd = shell_exec("DISPLAY=:0 /home/pi/refresh-browser.sh");

  2. $cmd = shell_exec("sudo pi 'DISPLAY=:0.0 xdotool key F5'");

TLDR: run xhost si:localuser:www-data

The issue is that the browser runs the php script with the user www-data , which is not authorized to access the X window system. To see what user is running the script, add echo shell_exec("whoami"); to your script.

You can also run the script from command line as www-data user, to see any errors that might not show in your browser, like this: sudo -u www-data php your_script_filename.php You can run xhost to see the access control status and authorized users, xhost + to disable it (not recommended, it completely deactivates authentication and allows everyone to access all applications on your screen), xhost - to (re)enable access control

SOLUTION: Add the www-data user to the authorized access list for the X server with:

xhost si:localuser:www-data

Testing:

pi@raspberrypi:/var/www/html $ export DISPLAY=:0
pi@raspberrypi:/var/www/html $ xhost
access control enabled, only authorized clients can connect
SI:localuser:pi
pi@raspberrypi:/var/www/html $ sudo -u www-data xdotool  getactivewindow
No protocol specified
Error: Can\'t open display: (null)
Failed creating new xdo instance
pi@raspberrypi:/var/www/html $ xhost si:localuser:www-data
localuser:www-data being added to access control list
pi@raspberrypi:/var/www/html $ xhost
access control enabled, only authorized clients can connect
SI:localuser:www-data
SI:localuser:pi
pi@raspberrypi:/var/www/html $ sudo -u www-data xdotool  getactivewindow
20971521

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM