Note that there are some explanatory texts on larger screens.

plurals
  1. POIs it possible to dynamically reload PHP code while script is running?
    primarykey
    data
    text
    <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>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. COI would generally store modifiable "config" information in a language agnostic format like an XML file and modify that. Then it should be a simple method call to reload the config file and an asset written in Java or Python (for example) can easily manipulate the server from the outside as well. As for dynamically changing the source code of a program? That seems like a bad idea in the first place ...
      singulars
    2. COI think what you should really be lookin' at is whether you really need one socket per player or if you can make the game more statefull instead. Thus instead of having an open connection from the client to the server, the client can send normal web requests. But I understand that would probably mean a total rewrite and is not an option at this point? Also, php does not support "undefining" classes, so if you have already defined class "Test", you cannot re-include a file to define class "Test" yet again.
      singulars
    3. COI think for all online games I know, when the administrator wants to apply an update to the game files, the server is reloaded and people are disconnected. Perhaps it would be better to have an online version where all the users connect to and a testing version where only you (or a handful of select people) will connect to. When you want the changes to go live, you save them to the online version and restart the server. This means you won't have to restart the online version for every small change you want to make.
      singulars
 

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