Many moons ago when I was getting started in programming, I coded a MUD (Multi User Dungeon - text based 'MMO' for back before the internet had pictures, for all you youngins!). It was written in C and I learned a ton, and one of the coolest things I learned while coding that mud was making the individual areas of code compiled as linked libraries (I believe thats what they are called? Its been a long time since I coded in C) and I was able to dynamically update/change the code of the game without ever having to shut it down/reboot it. Unlink the old library, move the new one in place, relink, turn that functionality back on.
Present day: I have a PHP command line script I have running that handles some server tasks. Before the lecture, yes, I know it's not the best/most efficient language to do this in. But due to certain factors, it's the language its done in right now.
The script I'm running actually runs on 4 different servers, and when it starts, there is a calling script that runs a wget to get the updated 'core' code from the main server, includes it, then runs it. Here's the code:
#!/usr/bin/php -q
<?php
echo "Grabbing latest code...
";
`wget -N http://blahblahblah.php`;
`wget -N http://blahblahothercode.php`;
include('blahblahblah.php');
?>
So my question - is it possible to, while it's running, have it update it's own code and reload itself? My current solution is for it to exit() after using a shell 'at' command to restart itself. Clunky, but it could accomplish the goal.
The problem there is when the script starts, it grabs an encryption key from stdin that must be typed in when the script starts. I don't ever want that key saved to disk anywhere (I don't want the key saved to a temp file to be read back in, or in any command history for 'at'). IDEALLY, I'd like to leave the key in memory and just 'replace' the running code. If thats even possible with PHP.
When we eventually redo this in C++ we have the option of libraries, but for now, is there any way to accomplish that in PHP?
Just had a thought right before I hit submit... when PHP hits an include command, does it do the include once when it runs, or will it run the include every time it sees it? That might be an option if I loop around an include...?