{"id":53597,"date":"2024-10-09T12:38:28","date_gmt":"2024-10-09T04:38:28","guid":{"rendered":"https:\/\/server.hk\/cnblog\/53597\/"},"modified":"2024-10-09T12:38:28","modified_gmt":"2024-10-09T04:38:28","slug":"php-%e5%b0%8d%e5%a4%96%e7%99%bc%e5%8c%85%e8%a7%a3%e6%b1%ba%e6%96%b9%e6%a1%88%ef%bc%88%e5%b0%8e%e8%87%b4-w3wp-exe-%e5%be%88%e5%8d%a0-cpu%ef%bc%89-2","status":"publish","type":"post","link":"https:\/\/server.hk\/cnblog\/53597\/","title":{"rendered":"PHP \u5c0d\u5916\u767c\u5305\u89e3\u6c7a\u65b9\u6848\uff08\u5c0e\u81f4 w3wp.exe \u5f88\u5360 CPU\uff09"},"content":{"rendered":"<h1 id=\"php-%e5%b0%8d%e5%a4%96%e7%99%bc%e5%8c%85%e8%a7%a3%e6%b1%ba%e6%96%b9%e6%a1%88%ef%bc%88%e5%b0%8e%e8%87%b4-w3wp-exe-%e5%be%88%e5%8d%a0-cpu%ef%bc%89-fsmgxYpbaN\">PHP \u5c0d\u5916\u767c\u5305\u89e3\u6c7a\u65b9\u6848\uff08\u5c0e\u81f4 w3wp.exe \u5f88\u5360 CPU\uff09<\/h1>\n<p>\u5728\u7576\u4eca\u7684\u7db2\u7d61\u74b0\u5883\u4e2d\uff0cPHP \u662f\u4e00\u7a2e\u5ee3\u6cdb\u4f7f\u7528\u7684\u4f3a\u670d\u5668\u7aef\u8173\u672c\u8a9e\u8a00\uff0c\u5c24\u5176\u662f\u5728\u958b\u767c\u52d5\u614b\u7db2\u7ad9\u548c\u7db2\u7d61\u61c9\u7528\u7a0b\u5e8f\u65b9\u9762\u3002\u7136\u800c\uff0c\u7576 PHP \u61c9\u7528\u7a0b\u5e8f\u7684\u6027\u80fd\u4e0d\u4f73\u6642\uff0c\u53ef\u80fd\u6703\u5c0e\u81f4\u4f3a\u670d\u5668\u8cc7\u6e90\u7684\u904e\u5ea6\u6d88\u8017\uff0c\u7279\u5225\u662f w3wp.exe \u9032\u7a0b\u7684 CPU \u4f7f\u7528\u7387\u904e\u9ad8\u3002\u672c\u6587\u5c07\u63a2\u8a0e PHP \u5c0d\u5916\u767c\u5305\u7684\u89e3\u6c7a\u65b9\u6848\uff0c\u4ee5\u6e1b\u5c11 w3wp.exe \u7684 CPU \u5360\u7528\u7387\u3002<\/p>\n<h2 id=\"%e4%bb%80%e9%ba%bc%e6%98%af-w3wp-exe%ef%bc%9f-fsmgxYpbaN\">\u4ec0\u9ebc\u662f w3wp.exe\uff1f<\/h2>\n<p>w3wp.exe \u662f Microsoft Internet Information Services (IIS) \u7684\u5de5\u4f5c\u9032\u7a0b\uff0c\u8ca0\u8cac\u8655\u7406\u6240\u6709\u7684 Web \u8acb\u6c42\u3002\u7576 PHP \u61c9\u7528\u7a0b\u5e8f\u904b\u884c\u4e0d\u7576\u6642\uff0cw3wp.exe \u53ef\u80fd\u6703\u6d88\u8017\u904e\u591a\u7684 CPU \u8cc7\u6e90\uff0c\u5c0e\u81f4\u4f3a\u670d\u5668\u6027\u80fd\u4e0b\u964d\uff0c\u5f71\u97ff\u7528\u6236\u9ad4\u9a57\u3002<\/p>\n<h2 id=\"php-%e5%b0%8d%e5%a4%96%e7%99%bc%e5%8c%85%e7%9a%84%e5%8e%9f%e5%9b%a0-fsmgxYpbaN\">PHP \u5c0d\u5916\u767c\u5305\u7684\u539f\u56e0<\/h2>\n<p>PHP \u5c0d\u5916\u767c\u5305\u901a\u5e38\u662f\u6307 PHP \u61c9\u7528\u7a0b\u5e8f\u5728\u8655\u7406\u8acb\u6c42\u6642\uff0c\u5411\u5916\u90e8\u670d\u52d9\u6216 API \u767c\u9001\u8acb\u6c42\u3002\u9019\u7a2e\u60c5\u6cc1\u4e0b\uff0c\u53ef\u80fd\u6703\u51fa\u73fe\u4ee5\u4e0b\u5e7e\u7a2e\u60c5\u6cc1\u5c0e\u81f4 CPU \u4f7f\u7528\u7387\u4e0a\u5347\uff1a<\/p>\n<ul>\n<li><strong>\u7121\u9650\u5faa\u74b0\u8acb\u6c42\uff1a<\/strong>\u5982\u679c PHP \u8173\u672c\u5728\u8655\u7406\u8acb\u6c42\u6642\u4e0d\u65b7\u767c\u9001\u8acb\u6c42\uff0c\u5c07\u5c0e\u81f4 CPU \u4f7f\u7528\u7387\u98c6\u5347\u3002<\/li>\n<li><strong>\u4e0d\u7576\u7684\u932f\u8aa4\u8655\u7406\uff1a<\/strong>\u672a\u80fd\u59a5\u5584\u8655\u7406\u5916\u90e8\u8acb\u6c42\u7684\u932f\u8aa4\uff0c\u53ef\u80fd\u5c0e\u81f4\u91cd\u8a66\u6a5f\u5236\u4e0d\u65b7\u89f8\u767c\u3002<\/li>\n<li><strong>\u9ad8\u983b\u7387\u7684\u8acb\u6c42\uff1a<\/strong>\u5982\u679c\u61c9\u7528\u7a0b\u5e8f\u983b\u7e41\u5730\u5411\u5916\u90e8\u670d\u52d9\u767c\u9001\u8acb\u6c42\uff0c\u5c07\u6703\u589e\u52a0 CPU \u7684\u8ca0\u64d4\u3002<\/li>\n<\/ul>\n<h2 id=\"%e8%a7%a3%e6%b1%ba%e6%96%b9%e6%a1%88-fsmgxYpbaN\">\u89e3\u6c7a\u65b9\u6848<\/h2>\n<p>\u70ba\u4e86\u964d\u4f4e w3wp.exe \u7684 CPU \u4f7f\u7528\u7387\uff0c\u53ef\u4ee5\u8003\u616e\u4ee5\u4e0b\u5e7e\u7a2e\u89e3\u6c7a\u65b9\u6848\uff1a<\/p>\n<h3 id=\"1-%e5%84%aa%e5%8c%96%e5%a4%96%e9%83%a8%e8%ab%8b%e6%b1%82-fsmgxYpbaN\">1. \u512a\u5316\u5916\u90e8\u8acb\u6c42<\/h3>\n<p>\u5728 PHP \u61c9\u7528\u7a0b\u5e8f\u4e2d\uff0c\u61c9\u8a72\u512a\u5316\u5c0d\u5916\u90e8 API \u7684\u8acb\u6c42\u3002\u4f8b\u5982\uff0c\u4f7f\u7528\u7de9\u5b58\u6280\u8853\u4f86\u6e1b\u5c11\u5c0d\u5916\u90e8\u670d\u52d9\u7684\u8acb\u6c42\u983b\u7387\u3002\u53ef\u4ee5\u4f7f\u7528 PHP \u7684 <code>APCu<\/code> \u6216 <code>Memcached<\/code> \u4f86\u7de9\u5b58\u7d50\u679c\uff0c\u5f9e\u800c\u6e1b\u5c11\u91cd\u8907\u8acb\u6c42\u7684\u6b21\u6578\u3002<\/p>\n<pre><code>\n$cacheKey = 'external_api_data';\n$data = apcu_fetch($cacheKey);\nif ($data === false) {\n    $data = file_get_contents('https:\/\/api.example.com\/data');\n    apcu_store($cacheKey, $data, 3600); \/\/ \u7de9\u5b58\u4e00\u5c0f\u6642\n}\n<\/code><\/pre>\n<h3 id=\"2-%e4%bd%bf%e7%94%a8%e7%95%b0%e6%ad%a5%e8%ab%8b%e6%b1%82-fsmgxYpbaN\">2. \u4f7f\u7528\u7570\u6b65\u8acb\u6c42<\/h3>\n<p>\u8003\u616e\u4f7f\u7528\u7570\u6b65\u8acb\u6c42\u4f86\u8655\u7406\u5916\u90e8 API \u7684\u8abf\u7528\u3002\u9019\u6a23\u53ef\u4ee5\u907f\u514d\u963b\u585e\u4e3b\u57f7\u884c\u7dd2\uff0c\u5f9e\u800c\u6e1b\u5c11 CPU \u7684\u4f7f\u7528\u7387\u3002\u53ef\u4ee5\u4f7f\u7528 <code>curl_multi_exec<\/code> \u4f86\u5be6\u73fe\u7570\u6b65\u8acb\u6c42\u3002<\/p>\n<pre><code>\n$multiHandle = curl_multi_init();\n$handles = [];\n\n\/\/ \u6dfb\u52a0\u591a\u500b\u8acb\u6c42\nforeach ($urls as $url) {\n    $ch = curl_init($url);\n    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);\n    curl_multi_add_handle($multiHandle, $ch);\n    $handles[] = $ch;\n}\n\n\/\/ \u57f7\u884c\u8acb\u6c42\ndo {\n    $status = curl_multi_exec($multiHandle, $active);\n    curl_multi_select($multiHandle);\n} while ($active &amp;&amp; $status == CURLM_CALL_MULTI_PERFORM);\n\n\/\/ \u7372\u53d6\u7d50\u679c\nforeach ($handles as $ch) {\n    $response = curl_multi_getcontent($ch);\n    curl_multi_remove_handle($multiHandle, $ch);\n    curl_close($ch);\n}\ncurl_multi_close($multiHandle);\n<\/code><\/pre>\n<h3 id=\"3-%e8%a8%ad%e7%bd%ae%e5%90%88%e7%90%86%e7%9a%84%e8%b6%85%e6%99%82-fsmgxYpbaN\">3. \u8a2d\u7f6e\u5408\u7406\u7684\u8d85\u6642<\/h3>\n<p>\u5728\u767c\u9001\u5916\u90e8\u8acb\u6c42\u6642\uff0c\u61c9\u8a2d\u7f6e\u5408\u7406\u7684\u8d85\u6642\u6642\u9593\uff0c\u4ee5\u9632\u6b62\u8acb\u6c42\u9577\u6642\u9593\u963b\u585e\u3002\u9019\u53ef\u4ee5\u901a\u904e\u8a2d\u7f6e <code>curl_setopt<\/code> \u7684 <code>CURLOPT_TIMEOUT<\/code> \u4f86\u5be6\u73fe\u3002<\/p>\n<pre><code>\ncurl_setopt($ch, CURLOPT_TIMEOUT, 10); \/\/ \u8a2d\u7f6e\u8d85\u6642\u70ba10\u79d2\n<\/code><\/pre>\n<h2 id=\"%e7%b8%bd%e7%b5%90-fsmgxYpbaN\">\u7e3d\u7d50<\/h2>\n<p>\u901a\u904e\u512a\u5316 PHP \u5c0d\u5916\u767c\u5305\u7684\u65b9\u5f0f\uff0c\u53ef\u4ee5\u6709\u6548\u964d\u4f4e w3wp.exe \u7684 CPU \u4f7f\u7528\u7387\uff0c\u5f9e\u800c\u63d0\u5347\u4f3a\u670d\u5668\u7684\u6574\u9ad4\u6027\u80fd\u3002\u9019\u4e9b\u89e3\u6c7a\u65b9\u6848\u4e0d\u50c5\u80fd\u6539\u5584\u61c9\u7528\u7a0b\u5e8f\u7684\u97ff\u61c9\u901f\u5ea6\uff0c\u9084\u80fd\u63d0\u9ad8\u7528\u6236\u9ad4\u9a57\u3002\u82e5\u60a8\u9700\u8981\u9032\u4e00\u6b65\u7684\u6280\u8853\u652f\u6301\u6216\u5c0b\u627e\u5408\u9069\u7684 <a href=\"https:\/\/server.hk\">\u9999\u6e2fVPS<\/a> \u89e3\u6c7a\u65b9\u6848\uff0c\u8acb\u8a2a\u554f\u6211\u5011\u7684\u7db2\u7ad9\u4ee5\u7372\u53d6\u66f4\u591a\u4fe1\u606f\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u63a2\u7d22 PHP \u5c0d\u5916\u767c\u5305\u89e3\u6c7a\u65b9\u6848\uff0c\u89e3\u6c7a w3wp.exe \u9ad8 CPU \u5360\u7528\u554f\u984c\uff0c\u63d0\u5347\u7db2\u7ad9\u6027\u80fd\u8207\u7a69\u5b9a\u6027\u3002<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4924],"tags":[],"class_list":["post-53597","post","type-post","status-publish","format-standard","hentry","category-setup-tutorials"],"_links":{"self":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/53597","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/comments?post=53597"}],"version-history":[{"count":1,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/53597\/revisions"}],"predecessor-version":[{"id":53598,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/53597\/revisions\/53598"}],"wp:attachment":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/media?parent=53597"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/categories?post=53597"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/tags?post=53597"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}