{"id":13566645,"url":"https://github.com/hide2/api","last_synced_at":"2025-04-04T00:31:48.143Z","repository":{"id":139268873,"uuid":"132873494","full_name":"hide2/api","owner":"hide2","description":"High performance api service","archived":false,"fork":false,"pushed_at":"2020-05-22T06:38:28.000Z","size":577,"stargazers_count":46,"open_issues_count":0,"forks_count":14,"subscribers_count":7,"default_branch":"master","last_synced_at":"2024-08-01T13:36:45.114Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/hide2.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null}},"created_at":"2018-05-10T08:45:05.000Z","updated_at":"2023-10-28T12:56:42.000Z","dependencies_parsed_at":null,"dependency_job_id":"64fda572-ddf9-4a03-9289-17c847ec081a","html_url":"https://github.com/hide2/api","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hide2%2Fapi","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hide2%2Fapi/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hide2%2Fapi/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hide2%2Fapi/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/hide2","download_url":"https://codeload.github.com/hide2/api/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":223075322,"owners_count":17083499,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-08-01T13:02:13.850Z","updated_at":"2024-11-04T21:30:44.124Z","avatar_url":"https://github.com/hide2.png","language":"PHP","funding_links":[],"categories":["PHP"],"sub_categories":[],"readme":"API\n========\nHigh performance api service\n\n单服开10+Worker，轻松支撑C100K请求\n\nWindows下安装PHP7\n========\n```\n下载最新PHP7.x http://windows.php.net/download/\n解压到任意目录，比如F:\\php\n将PHP的安装路径F:\\php加入PATH 环境变量\n进入PHP安装目录（例如 F:\\php）。找到php.ini-development文件并复制一份到当前目录，重命名为php.ini\n用编辑器打开 php.ini 文件，修改以下配置：\n去掉extension_dir = \"ext\"前面的分号（738 行左右）\n去掉extension=php_curl.dll前面的分号（893 行左右）\n去掉extension=php_mbstring.dll前面的分号（903 行左右）\n去掉extension=php_openssl.dll前面的分号（907 行左右）\n去掉extension=php_pdo_mysql.dll前面的分号（909 行左右）\n```\n\nMac下安装PHP7\n========\n```\nruby -e \"$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)\"\nbrew update\nbrew untap homebrew/php\nbrew uninstall php\nbrew upgrade\nbrew clenaup\nbrew prune\nbrew install autoconf\nbrew install php\n```\n\nCentOS7下部署\n========\n```\nsudo yum -y install epel-release\nsudo rpm -Uvh https://mirror.webtatic.com/yum/el7/webtatic-release.rpm\nsudo yum -y install git\nsudo yum install php71w php71w-devel php71w-cli php71w-common php71w-gd php71w-ldap php71w-mbstring php71w-mcrypt php71w-mysql php71w-pdo php71w-fpm php71w-pecl-redis -y\n\ncd ~\nsudo yum install gcc openssl openssl-devel libevent libevent-devel\nsudo pecl install event-2.3.0\nsudo vi /etc/php.d/sockets.ini\nextension=sockets.so\nextension=event.so\n\nsudo yum install redis\nsudo systemctl enable redis\nsudo systemctl start redis\n```\n\n安装Workerman的pcntl和posix扩展、event或者libevent扩展：http://doc.workerman.net/315116\n\n内核参数调优：http://doc.workerman.net/315302\n\n示例代码\n========\n```php\n/////////////////////////////////// http\n\u003c?php\nrequire_once __DIR__ . '/vendor/autoload.php';\nrequire_once __DIR__ . '/lib/app_http.php';\nrequire_once __DIR__ . '/config.php';\nini_set(\"precision\", \"-1\");\nini_set(\"serialize_precision\", \"-1\");\n\n$app = new App(\"http://0.0.0.0:8888\");\n$app-\u003ecount = 8;\n$app-\u003ename = 'api';\n\n$app-\u003eonWorkerStart = function ($worker) {\n\trequire_once __DIR__ . '/lib/auth.php';\n\trequire_once __DIR__ . '/lib/db.php';\n\trequire_once __DIR__ . '/lib/clickhouse.php';\n\trequire_once __DIR__ . '/lib/cache.php';\n\trequire_once __DIR__ . '/lib/kafka.php';\n\trequire_once __DIR__ . '/config.php';\n\tini_set(\"precision\", \"-1\");\n\tini_set(\"serialize_precision\", \"-1\");\n\n\techo \"[\" . date('Y-m-d H:i:s') . \"] Worker start[\" . $worker-\u003eid . \"]\\n\";\n};\n\n///////////////////////////////// API接口定义开始\n\n$app-\u003eget('/', function ($req) {\n\treturn 'OK';\n});\n\n$app-\u003epost('/', function ($req) {\n\treturn 'OK';\n});\n\n$app-\u003eget('/health/check', function ($req) {\n\treturn 'OK';\n});\n\n$app-\u003ebefore('/api', function ($req) {\n\treturn Auth::verify_api($req);\n});\n\n$app-\u003eget('/tables', function ($req) {\n\tif (CACHE::exists('tables')) {\n\t\treturn json_decode(CACHE::get('tables'));\n\t} else {\n\t\t$tables = DB::query('show tables');\n\t\tCACHE::set('tables', json_encode($tables), 5);\n\t\treturn json_decode(CACHE::get('tables'));\n\t}\n});\n\n///////////////////////////////// API接口定义结束\n\n\nApp::$logFile = './logs/workerman_api.log';\nApp::$stdoutFile = './logs/api.log';\n\nApp::runAll();\n```\n\n启动服务\n========\n```\nmkdir logs\nphp api.php start\n```\n压力测试\n```\nab -n 1000000 -c 1000 -k http://localhost:8888/\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhide2%2Fapi","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fhide2%2Fapi","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhide2%2Fapi/lists"}