'Swoole Compiler Loader 安装助手', ]; $languages['en'] = [ 'title' => 'Swoole Compiler Loader Wizard', ]; // Set env variable for current environment $env = []; // Check os type $env['os'] = []; if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') { $env['os']['name'] = "windows"; $env['os']['raw_name'] = php_uname(); } else { $env['os']['name'] = "unix"; $env['os']['raw_name'] = php_uname(); } // Check php $env['php'] = []; $env['php']['version'] = phpversion(); // Check run mode $sapi_type = php_sapi_name(); if ("cli" == $sapi_type) { $env['php']['run_mode'] = "cli"; } else { $env['php']['run_mode'] = "web"; } // Check php bit if (PHP_INT_SIZE == 4) { $env['php']['bit'] = 32; } else { $env['php']['bit'] = 64; } $env['php']['sapi'] = $sapi_type; $env['php']['ini_loaded_file'] = php_ini_loaded_file(); $env['php']['ini_scanned_files'] = php_ini_scanned_files(); $env['php']['loaded_extensions'] = get_loaded_extensions(); $env['php']['incompatible_extensions'] = ['xdebug', 'ionCube', 'zend_loader']; $env['php']['loaded_incompatible_extensions'] = []; $env['php']['extension_dir'] = ini_get('extension_dir'); // Check incompatible extensions if (is_array($env['php']['loaded_extensions'])) { foreach ($env['php']['loaded_extensions'] as $loaded_extension) { foreach ($env['php']['incompatible_extensions'] as $incompatible_extension) { if (strpos(strtolower($loaded_extension), strtolower($incompatible_extension)) !== false) { $env['php']['loaded_incompatible_extensions'][] = $loaded_extension; } } } } $env['php']['loaded_incompatible_extensions'] = array_unique($env['php']['loaded_incompatible_extensions']); // Parse System Environment Info $sysInfo = w_getSysInfo(); // Check php thread safety $env['php']['raw_thread_safety'] = isset($sysInfo['thread_safety']) ? $sysInfo['thread_safety'] : false; if (isset($sysInfo['thread_safety'])) { $env['php']['thread_safety'] = $sysInfo['thread_safety'] ? '线程安全' : '非线程安全'; } else { $env['php']['thread_safety'] = '未知'; } // Check swoole loader installation if (isset($sysInfo['swoole_loader']) and isset($sysInfo['swoole_loader_version'])) { $env['php']['swoole_loader']['status'] = $sysInfo['swoole_loader'] ? "已安装" : '未安装'; if ($sysInfo['swoole_loader_version'] !== false) { $env['php']['swoole_loader']['version'] = "" . $sysInfo['swoole_loader_version'] . ""; } else { $env['php']['swoole_loader']['version'] = '未知'; } } else { $env['php']['swoole_loader']['status'] = '未安装'; $env['php']['swoole_loader']['version'] = '未知'; } /** * Web mode */ if ('web' == $env['php']['run_mode']) { $language = substr($_SERVER['HTTP_ACCEPT_LANGUAGE'], 0, 4); if (preg_match("/zh-c/i", $language)) { $env['lang'] = "zh-cn"; $wizard_lang = $env['lang']; } else { $env['lang'] = "en"; $wizard_lang = $env['lang']; } $html = ''; // Header $html_header = ' %s '; $html_header = sprintf($html_header, $languages[$wizard_lang]['title']); $html_body = '
'; $html_body_nav = '
'; $html_body_nav .= '

CRMEB Swoole Compiler 安装向导

'; $html_body_nav .= '

Version:2.0.2 Date:2019-01-09

'; $html_body_nav .= '

'; // Environment information $html_body_environment = '
检查当前环境
'; // Error infomation $html_error = ""; if (!empty($env['php']['loaded_incompatible_extensions'])) { $html_error = '
错误信息

%s

'; $err_msg = "当前PHP包含与swoole_compiler_loader扩展不兼容的扩展" . implode(',', $env['php']['loaded_incompatible_extensions']) . ",请移除不兼容的扩展。"; $html_error = sprintf($html_error, $err_msg); } // Check Loader Status $html_body_loader = '
'; if (empty($html_error)) { $html_body_loader .= '
'; $html_body_loader .= '
安装和配置Swoole Loader
'; $phpversion = substr($env['php']['version'], 0, 3); $phpversion = str_replace('.', '', $phpversion); $loaderFileName = ''; if ($env['os']['name'] == "windows") { $loaderFileName = 'php_swoole_loader_php' . $phpversion; if ($env['php']['thread_safety'] == '非线程安全') { $loaderFileName .= '_nzts_x64.dll'; } else { $loaderFileName .= '_zts_x64.dll'; } } else { if ($env['php']['thread_safety'] != '非线程安全') { $loaderFileName = 'swoole_loader' . $phpversion . '_zts.so'; } else { $loaderFileName = 'swoole_loader' . $phpversion . '.so'; } } $html_body_loader .= '

1 - 安装Swoole Loader

前往根目录 /help/swoole-loader/' . $loaderFileName . '扩展文件上传到当前PHP的扩展安装目录中:

' . $env['php']['extension_dir'] . '

'; $html_body_loader .= '

2 - 修改php.ini配置(如已修改配置,请忽略此步骤,不必重复添加)

'; $html_body_loader .= '编辑此PHP配置文件:' . $env['php']['ini_loaded_file'] . ',在此文件底部结尾处加入如下配置
'; if ($env['os']['name'] == "windows") { $html_body_loader .= '

extension=' . $env['php']['extension_dir'] . DIRECTORY_SEPARATOR . $loaderFileName . '
注意:需要名称和刚才上传到当前PHP的扩展安装目录中的文件名一致'; } else { $html_body_loader .= '
extension=' . $env['php']['extension_dir'] . DIRECTORY_SEPARATOR . $loaderFileName . '
注意:需要名称和刚才上传到当前PHP的扩展安装目录中的文件名一致'; } $html_body_loader .= '

'; $html_body_loader .= '

3 - 重启服务

重启或重载PHP配置

'; $html_body_loader .= '
'; } // Body footer $html_body_footer = ''; $html_body .= $html_body_nav . '
' . $html_body_environment . $html_error . $html_body_loader . '
' . $html_body_footer; $html_body .= '
'; // Footer $html_footer = ' '; // Make full html $html = $html_header . $html_body . $html_footer; // Output html content //ob_start(); echo $html; //ob_end_clean(); //die(); } /** * Cli mode */ if ("cli" == $env['php']['run_mode']) { } /** * Useful functions */ // Dump detail of variable function w_dump($var) { if (is_object($var) and $var instanceof Closure) { $str = 'function ('; $r = new ReflectionFunction($var); $params = array(); foreach ($r->getParameters() as $p) { $s = ''; if ($p->isArray()) { $s .= 'array '; } else if ($p->getClass()) { $s .= $p->getClass()->name . ' '; } if ($p->isPassedByReference()) { $s .= '&'; } $s .= '$' . $p->name; if ($p->isOptional()) { $s .= ' = ' . var_export($p->getDefaultValue(), TRUE); } $params [] = $s; } $str .= implode(', ', $params); $str .= '){' . PHP_EOL; $lines = file($r->getFileName()); for ($l = $r->getStartLine(); $l < $r->getEndLine(); $l++) { $str .= $lines[$l]; } echo $str; return; } else if (is_array($var)) { echo ""; print_r($var); echo ""; return; } else { var_dump($var); return; } } // Parse verion of php function w_parse_version($version) { $versionList = []; if (is_string($version)) { $rawVersionList = explode('.', $version); if (isset($rawVersionList[0])) { $versionList[] = $rawVersionList[0]; } if (isset($rawVersionList[1])) { $versionList[] = $rawVersionList[1]; } } return $versionList; } function w_getSysInfo() { global $env; $sysEnv = []; // Get content of phpinfo ob_start(); phpinfo(); $sysInfo = ob_get_contents(); ob_end_clean(); // Explode phpinfo content if ($env['php']['run_mode'] == 'cli') { $sysInfoList = explode('\n', $sysInfo); } else { $sysInfoList = explode('', $sysInfo); } foreach ($sysInfoList as $sysInfoItem) { if (preg_match('/thread safety/i', $sysInfoItem)) { $sysEnv['thread_safety'] = (preg_match('/(enabled|yes)/i', $sysInfoItem) != 0); } if (preg_match('/swoole_loader support/i', $sysInfoItem)) { $sysEnv['swoole_loader'] = (preg_match('/(enabled|yes)/i', $sysInfoItem) != 0); } if (preg_match('/swoole_loader version/i', $sysInfoItem)) { preg_match('/\d+.\d+.\d+/s', $sysInfoItem, $match); $sysEnv['swoole_loader_version'] = isset($match[0]) ? $match[0] : false; } } //var_dump($sysEnv);die(); return $sysEnv; }