Example #1
0
 public function onStart($server)
 {
     echo '服务器启动: ' . date('Y-m-d H:i:s') . PHP_EOL;
     swoole_set_process_name('ExampleServer');
     //timer auto check
     $server->tick(500, function () {
         $path = dirname(__FILE__) . "/test";
         server_auto_reload($path, $this->_server);
         if ($this->_server->reload) {
             echo "Server auto reload \n";
             $this->_server->reload();
             $this->_server->reload = false;
         }
         $this->_server->first_start = false;
     });
 }
Example #2
0
File: swoole.php Project: sukui/tsf
function server_auto_reload($path, &$server)
{
    if (is_dir($path)) {
        $dp = dir($path);
        while ($file = $dp->read()) {
            if ($file != "." && $file != "..") {
                server_auto_reload($path . "/" . $file, $server);
            }
        }
        $dp->close();
    }
    if (is_file($path)) {
        $file_info = pathinfo($path);
        if (in_array($file_info['extension'], $server['conf']['setting']['watch_ext'])) {
            $hash = md5($path);
            $file_hash = md5_file($path);
            if (empty($server['hash'][$hash]) || $server['hash'][$hash] != $file_hash) {
                $server['hash'][$hash] = $file_hash;
                if (!$server['first_start']) {
                    $server['reload'] = true;
                }
            }
        }
    }
}