varspool / Wrench

A simple PHP WebSocket implementation for PHP 7.1
Do What The F*ck You Want To Public License
596 stars 210 forks source link

Possibility to stop server #77

Closed Alarmfifa closed 7 years ago

Alarmfifa commented 9 years ago

Right now if you start wrench server as $server->run() it launches an indefinite loop (while(true)). Only one way to stop it - kill the process. What about to add user possibility to control it? For example, I can write my own function, which listens process's signals or checks existing of some file. I want to pass this function to run() and stop looping when my function returns false. For compatibility it could look like:

    public function run(callable $finish = null)
    {
       ...        
        if (!is_callable($finish) ) {
            $finish = function() { return true; };
        }        
        while ( $finish() ) {
            ...        
        }        
    }

Of course, I can create my own Server class (which extends main class) and redefine function run(). But I'm not sure, that it will be more correctly, than add native support. @dominics what do you think? I would like to ask before making PR.