Почему tmux не может прочитать файл сеанса при запуске с PHP?Linux

Ответить
Гость
 Почему tmux не может прочитать файл сеанса при запуске с PHP?

Сообщение Гость »


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 with the PHP command.
The sessions will run under the user

Код: Выделить всё

www-data
, each running their separate task.
I 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
";
And that echoes

Код: Выделить всё

tmux -S /tmp/tmux-33/default ls
[ "error connecting to \/tmp\/tmux-33\/default (No such file or directory)" ]
That would mean that the file does not exist, right?
Well no. That's because If I open the terminal and run

Код: Выделить всё

sudo tmux -S /tmp/tmux-33/default ls
Than the output would be

Код: Выделить всё

0: 1 windows (created Sat Mar  9 18:09:34 2024)
2: 1 windows (created Sat Mar  9 18:16:42 2024) (attached)
Even reading the file with nano outputs

Код: Выделить всё

[ Error reading /tmp/tmux-33/default: No such device or address ]
, which proves the file exists.
And I can confirm that corresponds to

Код: Выделить всё

www-data
, because If I don't provide the -S parameter, It default to that file.
Another thing I tried to confirm that

Код: Выделить всё

www-data
is properly configured is connecting to It's shell directly as follows:

Код: Выделить всё

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$
So clearly the two sessions can be read by the apache account, but not from PHP with . I tried

Код: Выделить всё

shell_exec
as well, but that provided the same result.
It 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 function? I'd really appreciate some advice.
Thank you.


Источник: https://stackoverflow.com/questions/781 ... n-from-php
Ответить

Быстрый ответ

Изменение регистра текста: 
Смайлики
:) :( :oops: :roll: :wink: :muza: :clever: :sorry: :angel: :read: *x)
Ещё смайлики…
   
К этому ответу прикреплено по крайней мере одно вложение.

Если вы не хотите добавлять вложения, оставьте поля пустыми.

Максимально разрешённый размер вложения: 15 МБ.

Вернуться в «Linux»