{"id":46960,"date":"2024-12-02T16:02:06","date_gmt":"2024-12-02T08:02:06","guid":{"rendered":"https:\/\/fwq.ai\/blog\/46960\/"},"modified":"2024-12-02T16:02:06","modified_gmt":"2024-12-02T08:02:06","slug":"%e4%bc%98%e5%8c%96%e7%ac%ac%e4%b8%89%e6%96%b9-php-%e5%87%bd%e6%95%b0%e7%9a%84%e4%bd%bf%e7%94%a8%e4%bb%a5%e6%8f%90%e5%8d%87%e6%80%a7%e8%83%bd","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/46960\/","title":{"rendered":"\u4f18\u5316\u7b2c\u4e09\u65b9 PHP \u51fd\u6570\u7684\u4f7f\u7528\u4ee5\u63d0\u5347\u6027\u80fd"},"content":{"rendered":"<p><b><\/b> <\/p>\n<h1>\u4f18\u5316\u7b2c\u4e09\u65b9 PHP \u51fd\u6570\u7684\u4f7f\u7528\u4ee5\u63d0\u5347\u6027\u80fd<\/h1>\n<p>\u4ece\u73b0\u5728\u5f00\u59cb\uff0c\u6211\u4eec\u8981\u52aa\u529b\u5b66\u4e60\u5566\uff01\u4eca\u5929\u6211\u7ed9\u5927\u5bb6\u5e26\u6765<span style=\"color: #FF6600;, Helvetica, Arial, sans-serif;font-size: 14px;background-color: #FFFFFF\">\u300a\u4f18\u5316\u7b2c\u4e09\u65b9 PHP \u51fd\u6570\u7684\u4f7f\u7528\u4ee5\u63d0\u5347\u6027\u80fd\u300b<\/span>\uff0c\u611f\u5174\u8da3\u7684\u670b\u53cb\u8bf7\u7ee7\u7eed\u770b\u4e0b\u53bb\u5427\uff01\u4e0b\u6587\u4e2d\u7684\u5185\u5bb9\u6211\u4eec\u4e3b\u8981\u4f1a\u6d89\u53ca\u5230<span style=\"color: #FF6600;, Helvetica, Arial, sans-serif;font-size: 14px;background-color: #FFFFFF\"><\/span>\u7b49\u7b49\u77e5\u8bc6\u70b9\uff0c\u5982\u679c\u5728\u9605\u8bfb\u672c\u6587\u8fc7\u7a0b\u4e2d\u6709\u9047\u5230\u4e0d\u6e05\u695a\u7684\u5730\u65b9\uff0c\u6b22\u8fce\u7559\u8a00\u5440\uff01\u6211\u4eec\u4e00\u8d77\u8ba8\u8bba\uff0c\u4e00\u8d77\u5b66\u4e60\uff01<\/p>\n<p>\u4e3a\u4e86\u4f18\u5316\u7b2c\u4e09\u65b9 PHP \u51fd\u6570\u7684\u4f7f\u7528\u4ee5\u63d0\u5347\u6027\u80fd\uff0c\u53ef\u4ee5\u91c7\u53d6\u4ee5\u4e0b\u63aa\u65bd\uff1a\u7f13\u5b58\u51fd\u6570\u7ed3\u679c\uff0c\u4ee5\u52a0\u5feb\u9891\u7e41\u6267\u884c\u4e14\u7ed3\u679c\u4e0d\u53d8\u7684\u51fd\u6570\u3002\u4f7f\u7528\u61d2\u52a0\u8f7d\uff0c\u4ec5\u5728\u9700\u8981\u65f6\u52a0\u8f7d\u5927\u578b\u5e93\u3002\u8003\u8651\u4f7f\u7528\u66f4\u8f7b\u91cf\u7ea7\u7684\u66ff\u4ee3\u65b9\u6848\uff0c\u4ee5\u51cf\u5c11\u8d44\u6e90\u5360\u7528\u3002\u5c06\u51fd\u6570\u8c03\u7528\u5206\u7ec4\u5728\u4e00\u8d77\uff0c\u4ee5\u51cf\u5c11\u51fd\u6570\u67e5\u627e\u548c\u53c2\u6570\u7ed1\u5b9a\u6b21\u6570\u3002\u542f\u7528 JIT \u7f16\u8bd1\u5668\uff0c\u4ee5\u52a0\u901f\u51fd\u6570\u6267\u884c\u901f\u5ea6\u3002<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.17golang.com\/uploads\/20241025\/1729857211671b86bb1cacd.jpg\" class=\"aligncenter\" title=\"\u4f18\u5316\u7b2c\u4e09\u65b9 PHP \u51fd\u6570\u7684\u4f7f\u7528\u4ee5\u63d0\u5347\u6027\u80fd\u63d2\u56fe\" alt=\"\u4f18\u5316\u7b2c\u4e09\u65b9 PHP \u51fd\u6570\u7684\u4f7f\u7528\u4ee5\u63d0\u5347\u6027\u80fd\u63d2\u56fe\" \/><\/p>\n<p><strong>\u4f18\u5316\u7b2c\u4e09\u65b9 PHP \u51fd\u6570\u7684\u4f7f\u7528\u4ee5\u63d0\u5347\u6027\u80fd<\/strong><\/p>\n<p>\u7b2c\u4e09\u65b9 PHP \u51fd\u6570\u5e93\u53ef\u4ee5\u6781\u5927\u5730\u7b80\u5316\u4ee3\u7801\u5f00\u53d1\uff0c\u4f46\u5982\u679c\u4f7f\u7528\u4e0d\u5f53\uff0c\u5b83\u4eec\u4e5f\u4f1a\u5bf9\u6027\u80fd\u9020\u6210\u91cd\u5927\u5f71\u54cd\u3002\u53ef\u4ee5\u901a\u8fc7\u4ee5\u4e0b\u51e0\u79cd\u65b9\u6cd5\u4f18\u5316\u7b2c\u4e09\u65b9 PHP \u51fd\u6570\u7684\u4f7f\u7528\uff1a<\/p>\n<p><strong>1. \u7f13\u5b58\u51fd\u6570\u7ed3\u679c<\/strong><\/p>\n<p>\u5982\u679c\u7b2c\u4e09\u65b9\u51fd\u6570\u6267\u884c\u9891\u7e41\u4e14\u7ed3\u679c\u4fdd\u6301\u4e0d\u53d8\uff0c\u5219\u53ef\u4ee5\u901a\u8fc7\u7f13\u5b58\u7ed3\u679c\u6765\u663e\u8457\u63d0\u9ad8\u6027\u80fd\u3002\u53ef\u4ee5\u4f7f\u7528 [<code>cache_put()<\/code>](https:\/\/www.php.net\/manual\/zh\/function.cache-put.php) \u548c [<code>cache_get()<\/code>](https:\/\/www.php.net\/manual\/zh\/function.cache-get.php) \u51fd\u6570\u5c06\u7ed3\u679c\u5b58\u50a8\u5728 [opcode \u7f13\u5b58](https:\/\/www.php.net\/manual\/zh\/features.gc.performance-considerations.php) \u4e2d\u3002<\/p>\n<p><strong>\u5b9e\u4f8b\uff1a<\/strong><\/p>\n<pre>\/\/ \u5c06 curl_init() \u7684\u7ed3\u679c\u7f13\u5b58 60 \u79d2\n$ch = cache_get('curl_ch');\nif ($ch === false) {\n    $ch = curl_init();\n    cache_put('curl_ch', $ch, 60);\n}<\/pre>\n<p><strong>2. \u4f7f\u7528\u61d2\u52a0\u8f7d<\/strong><\/p>\n<p>\u907f\u514d\u5728\u4e0d\u9700\u8981\u65f6\u52a0\u8f7d\u5927\u578b\u7684\u7b2c\u4e09\u65b9\u5e93\u3002\u53ef\u4ee5\u4f7f\u7528 [Composer \u7684\u81ea\u52a8\u52a0\u8f7d\u5668](https:\/\/getcomposer.org\/doc\/01-basic-usage.md#autoloading) \u4ec5\u5728\u9700\u8981\u65f6\u52a0\u8f7d\u7c7b\u3002<\/p>\n<p><strong>\u5b9e\u4f8b\uff1a<\/strong><\/p>\n<p>\u5728 <code>composer.json<\/code> \u4e2d\u6dfb\u52a0\uff1a<\/p>\n<pre>\"autoload\": {\n    \"psr-4\": {\n        \"ThirdPartyLib\\\\\": \"path\/to\/library\/\"\n    }\n}<\/pre>\n<p>\u7136\u540e\uff0c\u5728\u4f60\u7684\u4ee3\u7801\u4e2d\u4f7f\u7528\uff1a<\/p>\n<pre>if (isset($_GET['use_third_party'])) {\n    require_once 'vendor\/autoload.php';\n    \/\/ \u52a0\u8f7d\u548c\u4f7f\u7528\u7c7b\n}<\/pre>\n<p><strong>3. \u4f7f\u7528\u8f7b\u91cf\u7ea7\u66ff\u4ee3\u65b9\u6848<\/strong><\/p>\n<p>\u8003\u8651\u4f7f\u7528\u66f4\u8f7b\u91cf\u7ea7\u7684\u7b2c\u4e09\u65b9\u5e93\uff0c\u5b83\u4eec\u63d0\u4f9b\u7c7b\u4f3c\u7684\u529f\u80fd\uff0c\u4f46\u5360\u7528\u8d44\u6e90\u66f4\u5c11\u3002\u4f8b\u5982\uff0c\u4f7f\u7528 [PsySH](https:\/\/psysh.org\/) \u4ee3\u66ff\u5b8c\u5168\u529f\u80fd\u7684 IDE\u3002<\/p>\n<p><strong>\u5b9e\u4f8b\uff1a<\/strong><\/p>\n<pre>\/\/ \u4f7f\u7528 PsySH \u4ee3\u66ff PHP CLI\npsy_shell();<\/pre>\n<p><strong>4. \u51cf\u5c11\u51fd\u6570\u8c03\u7528<\/strong><\/p>\n<p>\u5c3d\u53ef\u80fd\u5c06\u51fd\u6570\u8c03\u7528\u5206\u7ec4\u5728\u4e00\u8d77\u3002PHP \u6bcf\u6b21\u8c03\u7528\u51fd\u6570\u65f6\u90fd\u4f1a\u8fdb\u884c\u51fd\u6570\u67e5\u627e\u548c\u53c2\u6570\u7ed1\u5b9a\uff0c\u8fd9\u53ef\u80fd\u4f1a\u663e\u8457\u5f71\u54cd\u6027\u80fd\u3002<\/p>\n<p><strong>\u5b9e\u4f8b\uff1a<\/strong><\/p>\n<pre>\/\/ \u907f\u514d\u591a\u6b21\u8c03\u7528 trim() \u51fd\u6570\n$trimmedString = trim($string);\n\n\/\/  invece di:\n$noTrimmedString1 = trim($string);\n$noTrimmedString2 = trim($string);<\/pre>\n<p><strong>5. \u4f7f\u7528 JIT \u7f16\u8bd1\u5668<\/strong><\/p>\n<p>[JIT \u7f16\u8bd1\u5668](https:\/\/wiki.php.net\/rfc\/jit) \u53ef\u4ee5\u663e\u8457\u6539\u5584 PHP \u4ee3\u7801\u7684\u6027\u80fd\u3002\u5982\u679c\u53ef\u80fd\uff0c\u5e94\u542f\u7528 JIT \u7f16\u8bd1\u6765\u52a0\u901f\u7b2c\u4e09\u65b9\u51fd\u6570\u3002<\/p>\n<p><strong>\u5b9e\u4f8b\uff1a<\/strong><\/p>\n<p>\u5728 PHP CLI \u4e2d\u8fd0\u884c\uff1a<\/p>\n<pre>php -dopcache.jit=1 your_script.php<\/pre>\n<p>\u7ec8\u4e8e\u4ecb\u7ecd\u5b8c\u5566\uff01\u5c0f\u4f19\u4f34\u4eec\uff0c\u8fd9\u7bc7\u5173\u4e8e\u300a\u4f18\u5316\u7b2c\u4e09\u65b9 PHP \u51fd\u6570\u7684\u4f7f\u7528\u4ee5\u63d0\u5347\u6027\u80fd\u300b\u7684\u4ecb\u7ecd\u5e94\u8be5\u8ba9\u4f60\u6536\u83b7\u591a\u591a\u4e86\u5427\uff01\u6b22\u8fce\u5927\u5bb6\u6536\u85cf\u6216\u5206\u4eab\u7ed9\u66f4\u591a\u9700\u8981\u5b66\u4e60\u7684\u670b\u53cb\u5427~\u7c73\u4e91\u516c\u4f17\u53f7\u4e5f\u4f1a\u53d1\u5e03\u6587\u7ae0\u76f8\u5173\u77e5\u8bc6\uff0c\u5feb\u6765\u5173\u6ce8\u5427\uff01<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u4f18\u5316\u7b2c\u4e09\u65b9 PHP \u51fd\u6570\u7684\u4f7f\u7528\u4ee5\u63d0\u5347\u6027\u80fd \u4ece\u73b0\u5728\u5f00\u59cb\uff0c\u6211\u4eec\u8981\u52aa\u529b\u5b66\u4e60\u5566\uff01\u4eca\u5929\u6211\u7ed9\u5927\u5bb6\u5e26\u6765\u300a\u4f18\u5316\u7b2c\u4e09\u65b9 PHP \u51fd\u6570\u7684\u4f7f\u7528\u4ee5\u63d0\u5347\u6027\u80fd\u300b\uff0c\u611f\u5174\u8da3\u7684\u670b\u53cb\u8bf7\u7ee7\u7eed\u770b\u4e0b\u53bb\u5427\uff01\u4e0b\u6587\u4e2d\u7684\u5185\u5bb9\u6211\u4eec\u4e3b\u8981\u4f1a\u6d89\u53ca\u5230\u7b49\u7b49\u77e5\u8bc6\u70b9\uff0c\u5982\u679c\u5728\u9605\u8bfb\u672c\u6587\u8fc7\u7a0b\u4e2d\u6709\u9047\u5230\u4e0d\u6e05\u695a\u7684\u5730\u65b9\uff0c\u6b22\u8fce\u7559\u8a00\u5440\uff01\u6211\u4eec\u4e00\u8d77\u8ba8\u8bba\uff0c\u4e00\u8d77\u5b66\u4e60\uff01 \u4e3a\u4e86\u4f18\u5316\u7b2c\u4e09\u65b9 PHP \u51fd\u6570\u7684\u4f7f\u7528\u4ee5\u63d0\u5347\u6027\u80fd\uff0c\u53ef\u4ee5\u91c7\u53d6\u4ee5\u4e0b\u63aa\u65bd\uff1a\u7f13\u5b58\u51fd\u6570\u7ed3\u679c\uff0c\u4ee5\u52a0\u5feb\u9891\u7e41\u6267\u884c\u4e14\u7ed3\u679c\u4e0d\u53d8\u7684\u51fd\u6570\u3002\u4f7f\u7528\u61d2\u52a0\u8f7d\uff0c\u4ec5\u5728\u9700\u8981\u65f6\u52a0\u8f7d\u5927\u578b\u5e93\u3002\u8003\u8651\u4f7f\u7528\u66f4\u8f7b\u91cf\u7ea7\u7684\u66ff\u4ee3\u65b9\u6848\uff0c\u4ee5\u51cf\u5c11\u8d44\u6e90\u5360\u7528\u3002\u5c06\u51fd\u6570\u8c03\u7528\u5206\u7ec4\u5728\u4e00\u8d77\uff0c\u4ee5\u51cf\u5c11\u51fd\u6570\u67e5\u627e\u548c\u53c2\u6570\u7ed1\u5b9a\u6b21\u6570\u3002\u542f\u7528 JIT \u7f16\u8bd1\u5668\uff0c\u4ee5\u52a0\u901f\u51fd\u6570\u6267\u884c\u901f\u5ea6\u3002 \u4f18\u5316\u7b2c\u4e09\u65b9 PHP \u51fd\u6570\u7684\u4f7f\u7528\u4ee5\u63d0\u5347\u6027\u80fd \u7b2c\u4e09\u65b9 PHP \u51fd\u6570\u5e93\u53ef\u4ee5\u6781\u5927\u5730\u7b80\u5316\u4ee3\u7801\u5f00\u53d1\uff0c\u4f46\u5982\u679c\u4f7f\u7528\u4e0d\u5f53\uff0c\u5b83\u4eec\u4e5f\u4f1a\u5bf9\u6027\u80fd\u9020\u6210\u91cd\u5927\u5f71\u54cd\u3002\u53ef\u4ee5\u901a\u8fc7\u4ee5\u4e0b\u51e0\u79cd\u65b9\u6cd5\u4f18\u5316\u7b2c\u4e09\u65b9 PHP \u51fd\u6570\u7684\u4f7f\u7528\uff1a 1. \u7f13\u5b58\u51fd\u6570\u7ed3\u679c \u5982\u679c\u7b2c\u4e09\u65b9\u51fd\u6570\u6267\u884c\u9891\u7e41\u4e14\u7ed3\u679c\u4fdd\u6301\u4e0d\u53d8\uff0c\u5219\u53ef\u4ee5\u901a\u8fc7\u7f13\u5b58\u7ed3\u679c\u6765\u663e\u8457\u63d0\u9ad8\u6027\u80fd\u3002\u53ef\u4ee5\u4f7f\u7528 [cache_put()](https:\/\/www.php.net\/manual\/zh\/function.cache-put.php) \u548c [cache_get()](https:\/\/www.php.net\/manual\/zh\/function.cache-get.php) \u51fd\u6570\u5c06\u7ed3\u679c\u5b58\u50a8\u5728 [opcode \u7f13\u5b58](https:\/\/www.php.net\/manual\/zh\/features.gc.performance-considerations.php) \u4e2d\u3002 \u5b9e\u4f8b\uff1a \/\/ \u5c06 curl_init() \u7684\u7ed3\u679c\u7f13\u5b58 60 \u79d2 $ch = cache_get(&#8216;curl_ch&#8217;); if ($ch === false) { $ch = curl_init(); cache_put(&#8216;curl_ch&#8217;, $ch, 60); } 2. \u4f7f\u7528\u61d2\u52a0\u8f7d \u907f\u514d\u5728\u4e0d\u9700\u8981\u65f6\u52a0\u8f7d\u5927\u578b\u7684\u7b2c\u4e09\u65b9\u5e93\u3002\u53ef\u4ee5\u4f7f\u7528 [Composer [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[16],"tags":[],"class_list":["post-46960","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/46960","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/comments?post=46960"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/46960\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=46960"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=46960"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=46960"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}