function copy_dir($source, $destination) { if (!is_dir($destination)) { mymkdir($destination); } if ($source[strlen($source) - 1] == '/') { $source = substr($source, 0, -1); } if ($destination[strlen($destination) - 1] == '/') { $destination = substr($destination, 0, -1); } if ($handle = opendir($source)) { while (($entry = readdir($handle)) !== false) { if ($entry != "." && $entry != "..") { if (is_dir($source . "/" . $entry)) { copy_dir($source . "/" . $entry, $destination . "/" . $entry); } else { if (!copy($source . "/" . $entry, $destination . "/" . $entry)) { echo " <font color=\"red\">copy_dir错误</font>:无法复制文件{$source}/{$entry}到{$destination}/{$entry}。<br>"; } } } } } else { echo ' <font color=\\"red\\">copy_dir错误</font>: 进入目录' . $source . '失败。<br>'; } }
} while (1) { $___TEMP_CONN_PORT_TRY = rand($___MOD_CONN_PORT_LOW, $___MOD_CONN_PORT_HIGH); __SOCKET_DEBUGLOG__("正在尝试绑定端口" . $___TEMP_CONN_PORT_TRY . "..."); if (socket_bind($___TEMP_socket, '127.0.0.1', $___TEMP_CONN_PORT_TRY) === false) { __SOCKET_DEBUGLOG__("绑定端口" . $___TEMP_CONN_PORT_TRY . '失败。(' . socket_strerror(socket_last_error()) . ')'); } else { __SOCKET_LOG__("绑定端口" . $___TEMP_CONN_PORT_TRY . '成功。'); $___TEMP_CONN_PORT = $___TEMP_CONN_PORT_TRY; break; } } if (socket_listen($___TEMP_socket) === false) { __SOCKET_ERRORLOG__('socket_listen失败。'); } mymkdir(GAME_ROOT . './gamedata/tmp/server/' . $___TEMP_CONN_PORT); //进入闲置状态 if (file_exists(GAME_ROOT . './gamedata/tmp/server/' . $___TEMP_CONN_PORT . '/busy')) { unlink(GAME_ROOT . './gamedata/tmp/server/' . $___TEMP_CONN_PORT . '/busy'); } //__SOCKET_WARNLOG__("file: ".xdebug_get_profiler_filename()); __SOCKET_DEBUGLOG__("开始监听端口.."); while (true) { if (!__SOCKET_CHECK_WITH_TIMEOUT__($___TEMP_socket, 'a', $___MOD_SRV_WAKETIME, 0)) { $___TEMP_runned_time = time() - $___TEMP_server_start_time; if ($___TEMP_runned_time + $___MOD_SRV_WAKETIME + 5 > $___TEMP_max_time) { //没有下一次唤醒了,主动退出 __SOCKET_LOG__("已经运行了 " . $___TEMP_runned_time . "秒。主动退出。"); if (!$___TEMP_newsrv_flag) { __SOCKET_LOG__("由于过长时间没有收到命令且不是惟一的服务器,没有要求启动替代者。"); }
function writeoutput2($file, $string, $mode = "w", $debug = true) { $file = removeDoubleSlash($file); if ($debug) { echo "\n" . __FUNCTION__ . ":*** Writing to file ({$file}) the contents:\n\n{$string}\n\n"; } mymkdir(dirname($file)); # auto make the dir of filename if (!($fp = fopen($file, $mode))) { echo "hata: dosya acilamadi: {$file} (writeoutput) !"; return false; } if (!fputs($fp, $string . "\n")) { fclose($fp); echo "hata: dosyaya yazilamadi: {$file} (writeoutput) !"; return false; } fclose($fp); return true; }