Reputation: 101
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:
$cmd = shell_exec("DISPLAY=:0 /home/pi/refresh-browser.sh");
$cmd = shell_exec("sudo pi 'DISPLAY=:0.0 xdotool key F5'");
Upvotes: 0
Views: 575
Reputation: 11
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
Upvotes: 1