I am running some complex PHP scripts, and one thing I am experimenting with is launching a child/worker script to do something, while the main script goes on to do other stuff(launching and detaching a program).
I found out that I can use PHP's popen function to run a process, use fwrite() to write data to that process, then pclose() to close it.
Ok, fine.
Code: Select all
//open child process
$child = popen('php ./snapshot_child.php','w');
fwrite($child,serialize($input)."\n".serialize($names['known'])."\n".serialize($names['unknown']));
pclose($child);
Alright, I thought, why not use screen to separate it? I know that I can use screen php ./script.php to launch a script that doesn't end if you close your SSH window.
I found out that screen -dm will auto-detatch, which is what I want.
Code: Select all
//open child process
$child = popen('screen -dm php ./snapshot_child.php','w');
fwrite($child,serialize($input)."\n".serialize($names['known'])."\n".serialize($names['unknown']));
pclose($child);
I know I could simply make a temp file, save the data I want to pass in it, then open it in the child... but that seems cludgy.
Any thoughts?
Note: I am running CentOS on a VPS.
edit:
this might seem like a PHP question, but the PHP parts I have - I just don't know much about pipes, passing data, screen, and launching programs, which I am having trouble with.
-RobbieThe1st