workerman 学习记录
Linux系统环境检测
Linux系统可以使用以下脚本测试本机PHP环境是否满足WorkerMan运行要求。
curl -Ss http://www.workerman.net/check.php | php
check.php
<?php $version_ok = $pcntl_loaded = $posix_loaded = false; if (version_compare(phpversion(), "5.3.3", ">=")) { $version_ok = true; } if (in_array("pcntl", get_loaded_extensions())) { $pcntl_loaded = true; } if (in_array("posix", get_loaded_extensions())) { $posix_loaded = true; } function check($val) { if ($val) { return "\033[32;40m [OK] \033[0m\n"; } else { return "\033[31;40m [fail] \033[0m\n"; } } echo "PHP Version >= 5.3.3 " . check($version_ok); echo "Extension pcntl check " . check($pcntl_loaded); echo "Extension posix check " . check($posix_loaded); $check_func_map = array( "stream_socket_server", "stream_socket_client", "pcntl_signal_dispatch", "pcntl_signal", "pcntl_alarm", "pcntl_fork", "posix_getuid", "posix_getpwuid", "posix_kill", "posix_setsid", "posix_getpid", "posix_getpwnam", "posix_getgrnam", "posix_getgid", "posix_setgid", "posix_initgroups", "posix_setuid", "posix_isatty", ); // 获取php.ini中设置的禁用函数 if ($disable_func_string = ini_get("disable_functions")) { $disable_func_map = array_flip(explode(",", $disable_func_string)); } // 遍历查看是否有禁用的函数 foreach ($check_func_map as $func) { if (isset($disable_func_map[$func])) { echo "\n\033[31;40mFunction $func may be disabled. Please check disable_functions in php.ini\n"; echo "see http://doc.workerman.net/faq/disable-function-check.html\033[0m\n"; exit; } }
脚本如果全部显示ok,则代表满足WorkerMan要求
如果不是全部ok,则参考下面文档安装缺失的扩展即可。(注意:检测脚本中没有检测event扩展或者libevent扩展,如果业务并发连接数大于1024必须安装event扩展或者libevent扩展,并且优化Linux内核
linux特殊含义的转义符\033
格式: echo -e "\033[字背景颜色;字体颜色m字符串\033[0m" 例如: echo -e "\033[41;36m something here \033[0m" 其中41的位置代表底色, 36的位置是代表字的颜色 那些ascii code 是对颜色调用的始末. \033[XX; m …… \033[0m #XX表示下面的数字 字颜色:30-----------37 30:黑 31:红 32:绿 33:黄 34:蓝色 35:紫色 36:深绿 37:白色 字背景颜色范围:40----47 40:黑 41:深红 42:绿 43:黄色 44:蓝色 45:紫色 46:深绿 47:白色 字体加亮颜色:90------------97 90:黑 91:红 92:绿 93:黄 94:蓝色 95:紫色 96:深绿 97:白色 背景加亮颜色范围:100--------------------107 40:黑 41:深红 42:绿 43:黄色 44:蓝色 45:紫色 46:深绿 47:白色 ANSI控制码的说明 \33[0m 关闭所有属性 \33[1m 设置高亮度 \33[4m 下划线 \33[5m 闪烁 \33[7m 反显 \33[8m 消隐 \33[30m -- \33[37m 设置前景色 \33[40m -- \33[47m 设置背景色 \33[nA 光标上移n行 \33[nB 光标下移n行 \33[nC 光标右移n行 \33[nD 光标左移n行 \33[y;xH设置光标位置 \33[2J 清屏 \33[K 清除从光标到行尾的内容 \33[s 保存光标位置 \33[u 恢复光标位置 \33[?25l 隐藏光标 \33[?25h 显示光标 \x1b[2J\x1b[$;1H $表示行位
fix.php
<?php $disable_functions_str = ini_get("disable_functions"); if (!$disable_functions_str) { exit("ok\n"); } $functions_required = [ "pcntl_", "posix_", "stream_", ]; $has_disbaled_functions = false; foreach ($functions_required as $func) { if (strpos($disable_functions_str, $func) !== false) { $has_disbaled_functions = true; break; } } if (!$has_disbaled_functions) { exit("ok\n"); } $disable_functions = explode(",", $disable_functions_str); $disable_functions_removed = []; foreach ($disable_functions as $index => $func) { $func = trim($func); foreach ($functions_required as $func_prefix) { if (strpos($func, $func_prefix) === 0) { $disable_functions_removed[$func] = $func; unset($disable_functions[$index]); } } } $php_ini_file = PHP_CONFIG_FILE_PATH . "/php.ini"; if (!is_file($php_ini_file)) { exit("$php_ini_file not found\n"); } $php_ini_content = file_get_contents($php_ini_file); if (!$php_ini_content) { exit("$php_ini_file content empty\n"); } $new_disable_functions_str = implode(",", $disable_functions); $php_ini_content = preg_replace("/\ndisable_functions *?=[^\n]+/", "\ndisable_functions = $new_disable_functions_str", $php_ini_content); file_put_contents($php_ini_file, $php_ini_content); foreach ($disable_functions_removed as $func) { echo DIRECTORY_SEPARATOR === "/" ? "$func \033[32;40m [enabled] \033[0m\r\n" : "$func [enabled]\r\n"; } echo "\r\nsuccess\r\n";
分情破爱始乱弃,流落天涯思别离。
如花似玉负情意,影如白昼暗自迷。
随风浮沉千叶落,行色匆匆鬓已稀。

浙公网安备 33010602011771号