Note that there are some explanatory texts on larger screens.

plurals
  1. POIs it possible to dynamically reload PHP code while script is running?
    text
    copied!<p>I'm having a multiplayer server that's using PHPSockets, and thus is written entirely in PHP.</p> <p>Currently, whenever I'm making any changes to the PHP server-script I have to kill the script and then start it over again. This means that any users online is disconnected (normally not a problem because there aren't so many at the moment).</p> <p>Now I am rewriting the server-script to use custom PHP classes and sorten things up a little bit (you don't want to know how nasty it looks today). Today I was thinking: "Shouldn't it be possible to make changes to the php source without having to restart the whole script?".</p> <p>For example, I'm planning on having a <code>main.php</code> file that is including <code>user.php</code> which contains the class <code>MyUser</code> and <code>game.php</code> which contains the class <code>MyGame</code>. <strong>Now let's say that I would like to make a change to <code>user.php</code> and "reload" the server so that the changes to <code>user.php</code> goes into effect, without disconnecting any online users?</strong></p> <p>I tried to find other questions that answered this, the closest I got is this question: <a href="https://stackoverflow.com/questions/6068359/modifying-a-running-script-and-having-it-reload-without-killing-it-php">Modifying a running script and having it reload without killing it (php)</a> , which however doesn't seem to solve the disconnection of online users.</p> <p><strong>UPDATE</strong></p> <p>My own solutions to this were:</p> <ol> <li>At special occations, include the file external.php, which can access a few variables and use them however it'd like. When doing this, I had to make sure that there were no errors in the code as the whole server would crash if I tried accessing a method that did not exist.</li> <li><strong>Rewrite the whole thing to Java</strong>, which gave me the possibility of adding a plugin system using dynamic class reloading. Works like a charm. Bye bye PHP.</li> </ol>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload