php - Create Linux Screen session and get its PID -
i'm trying create php wrapper class around linux screen utility. need able start screen session name , pid of screen created.
i cannot assume session name unique can't parse session -ls output find pid.
based on examples , suggestions around internet, have tried following approach using php's exec() function:
screen -d -m -s 'screen_name' 2>&1 & the -d parameter tells screen not fork process, has same pid background process.
so, can parse pid output of & background shell operator in format:
[<number>] <pid> this command works linux shell (terminates immediately), when run php freezes , browser never loads page.
i have tried executing both php's exec() , shell_exec() , it's same result.
i have tried lots of different combinations last part of command such ones described here.
edit:
if use command:
screen -d -m -s 'screen_name' 1> /dev/null 2> /dev/null & 2>&1 then php exec() works. starts screen session don't output & background operator. i'm assuming it's because i'm redirecting stdout , stderr /dev/null far know should doing screen command, not & operator.
almost solution:
screen -d -m -s 'screen_name' 1> /dev/null 2> /dev/null & echo $! i realized text showing in terminal & background operator wasn't coming command stdout or stderr. it's shell displaying it. added echo $! after & operator print pid of process created last command.
this works in terminal, prints correct pid. when it's executed in php, actual screen pid value 4 more 1 returned echo. it's echo being executed before & operator. there way make wait?
solution:
i wrapping command in sudo, , background operator acting on sudo command instead of screen command. make sure escape command arguments! :)
almost solution:
screen -d -m -s 'screen_name' 1> /dev/null 2> /dev/null & echo $! i realized text showing in terminal & background operator wasn't coming command stdout or stderr. it's shell displaying it. added echo $! after & operator print pid of process created last command.
this works in terminal, prints correct pid. when it's executed in php, actual screen pid value 4 more 1 returned echo. it's echo being executed before & operator. there way make wait?
solution:
i wrapping command in sudo, , background operator acting on sudo command instead of screen command. make sure escape command arguments! :)
– bradley odell
Comments
Post a Comment