I want to create a PHP site which can manage multiple sessions and read contents from them. So in order to realize this I decided to use
Код: Выделить всё
tmuxКод: Выделить всё
exec()The sessions will run under the user
Код: Выделить всё
www-dataI use the following code to get a list of all running sessions in PHP:
Код: Выделить всё
$command = "tmux -S /tmp/tmux-33/default ls";
$command."
";
exec($command . " 2>&1", $output, $result_code);
$output = JSON_Format($output);
echo "$output
";
Код: Выделить всё
tmux -S /tmp/tmux-33/default ls
[ "error connecting to \/tmp\/tmux-33\/default (No such file or directory)" ]
Well no. That's because If I open the terminal and run
Код: Выделить всё
sudo tmux -S /tmp/tmux-33/default ls
Код: Выделить всё
0: 1 windows (created Sat Mar 9 18:09:34 2024)
2: 1 windows (created Sat Mar 9 18:16:42 2024) (attached)
Код: Выделить всё
[ Error reading /tmp/tmux-33/default: No such device or address ]And I can confirm that
Код: Выделить всё
tmux-33Код: Выделить всё
www-dataAnother thing I tried to confirm that
Код: Выделить всё
www-dataКод: Выделить всё
codrut@Linux-Server:/tmp$ sudo -u www-data -s /bin/bash
www-data@Linux-Server:/tmp$ tmux list-s
0: 1 windows (created Sat Mar 9 18:09:34 2024)
2: 1 windows (created Sat Mar 9 18:16:42 2024) (attached)
www-data@Linux-Server:/tmp$
Код: Выделить всё
execКод: Выделить всё
shell_execIt also seems the user superfuzzy also had this issue. For them, downgrading to PHP 7.1 fixed the error. I am running PHP 8.3.3-1. Unfortunately, I cannot afford to downgrade to an older version, as much of my website infrastructure relies on new functions introduced in PHP 8.
The user superfuzzy also noticed the following
Another weird thing: when launching the tmux sessions over php the terminal has no user and no location
Normally it looks like user@machinename$ ...
With php it just looks like $ ... nothing more
And after a bit of digging, I found that this is caused by the fact that Apache2 uses '/bin/sh' as the shell. Which in Ubuntu, does not default to '/bin/bash' but to '/bin/dash', which from my understanding is a more lightweight and faster version of bash with a little less features. But from my testing, this should not affect tmux in any way.
So is there anything I can do, or maybe some alternatives to the
Код: Выделить всё
exec()Thank you.
Источник: https://stackoverflow.com/questions/781 ... n-from-php
Мобильная версия