{"id":144113,"date":"2024-11-01T07:15:26","date_gmt":"2024-10-31T23:15:26","guid":{"rendered":"https:\/\/server.hk\/cnblog\/144113\/"},"modified":"2024-11-01T07:15:27","modified_gmt":"2024-10-31T23:15:27","slug":"thinkphp-%e6%95%b8%e6%93%9a%e5%ba%ab%e5%bf%ab%e5%8f%96%ef%bc%9a%e5%84%aa%e5%8c%96%e6%82%a8%e7%9a%84%e7%b6%b2%e7%ab%99%e9%80%9f%e5%ba%a6-thinkphp-%e6%95%b8%e6%93%9a%e5%ba%ab-%e5%bf%ab%e5%8f%96","status":"publish","type":"post","link":"https:\/\/server.hk\/cnblog\/144113\/","title":{"rendered":"ThinkPHP \u6578\u64da\u5eab\u5feb\u53d6\uff1a\u512a\u5316\u60a8\u7684\u7db2\u7ad9\u901f\u5ea6 (thinkphp \u6578\u64da\u5eab \u5feb\u53d6)"},"content":{"rendered":"<h1 id=\"thinkphp-%e6%95%b8%e6%93%9a%e5%ba%ab%e5%bf%ab%e5%8f%96%ef%bc%9a%e5%84%aa%e5%8c%96%e6%82%a8%e7%9a%84%e7%b6%b2%e7%ab%99%e9%80%9f%e5%ba%a6-shbOMteZhb\">ThinkPHP \u6578\u64da\u5eab\u5feb\u53d6\uff1a\u512a\u5316\u60a8\u7684\u7db2\u7ad9\u901f\u5ea6<\/h1>\n<p>\u5728\u7576\u4eca\u7684\u7db2\u7d61\u74b0\u5883\u4e2d\uff0c\u7db2\u7ad9\u901f\u5ea6\u5c0d\u65bc\u7528\u6236\u9ad4\u9a57\u548c\u641c\u7d22\u5f15\u64ce\u6392\u540d\u81f3\u95dc\u91cd\u8981\u3002\u4f7f\u7528 ThinkPHP \u6846\u67b6\u7684\u958b\u767c\u8005\u53ef\u4ee5\u901a\u904e\u6578\u64da\u5eab\u5feb\u53d6\u6280\u8853\u4f86\u986f\u8457\u63d0\u9ad8\u7db2\u7ad9\u7684\u6027\u80fd\u3002\u672c\u6587\u5c07\u63a2\u8a0e ThinkPHP \u7684\u6578\u64da\u5eab\u5feb\u53d6\u6a5f\u5236\u53ca\u5176\u512a\u5316\u7db2\u7ad9\u901f\u5ea6\u7684\u65b9\u5f0f\u3002<\/p>\n<h2 id=\"%e4%bb%80%e9%ba%bc%e6%98%af%e6%95%b8%e6%93%9a%e5%ba%ab%e5%bf%ab%e5%8f%96%ef%bc%9f-shbOMteZhb\">\u4ec0\u9ebc\u662f\u6578\u64da\u5eab\u5feb\u53d6\uff1f<\/h2>\n<p>\u6578\u64da\u5eab\u5feb\u53d6\u662f\u4e00\u7a2e\u5c07\u67e5\u8a62\u7d50\u679c\u5b58\u5132\u5728\u5167\u5b58\u4e2d\u7684\u6280\u8853\uff0c\u4ee5\u4fbf\u5728\u5f8c\u7e8c\u8acb\u6c42\u4e2d\u5feb\u901f\u8a2a\u554f\u3002\u9019\u6a23\u53ef\u4ee5\u6e1b\u5c11\u5c0d\u6578\u64da\u5eab\u7684\u76f4\u63a5\u67e5\u8a62\uff0c\u5f9e\u800c\u964d\u4f4e\u5ef6\u9072\u548c\u63d0\u9ad8\u97ff\u61c9\u901f\u5ea6\u3002ThinkPHP \u63d0\u4f9b\u4e86\u591a\u7a2e\u5feb\u53d6\u65b9\u5f0f\uff0c\u5305\u62ec\u6587\u4ef6\u5feb\u53d6\u3001\u5167\u5b58\u5feb\u53d6\uff08\u5982 Redis \u548c Memcached\uff09\u7b49\u3002<\/p>\n<h2 id=\"thinkphp-%e7%9a%84%e5%bf%ab%e5%8f%96%e6%a9%9f%e5%88%b6-shbOMteZhb\">ThinkPHP \u7684\u5feb\u53d6\u6a5f\u5236<\/h2>\n<p>ThinkPHP \u7684\u5feb\u53d6\u7cfb\u7d71\u975e\u5e38\u9748\u6d3b\uff0c\u958b\u767c\u8005\u53ef\u4ee5\u6839\u64da\u9700\u6c42\u9078\u64c7\u4e0d\u540c\u7684\u5feb\u53d6\u9a45\u52d5\u3002\u4ee5\u4e0b\u662f\u4e00\u4e9b\u5e38\u7528\u7684\u5feb\u53d6\u9a45\u52d5\uff1a<\/p>\n<ul>\n<li><strong>\u6587\u4ef6\u5feb\u53d6\uff1a<\/strong>\u5c07\u5feb\u53d6\u6578\u64da\u5b58\u5132\u5728\u6587\u4ef6\u7cfb\u7d71\u4e2d\uff0c\u9069\u5408\u5c0f\u578b\u61c9\u7528\u3002<\/li>\n<li><strong>Redis\uff1a<\/strong>\u4e00\u7a2e\u9ad8\u6548\u7684\u5167\u5b58\u6578\u64da\u5eab\uff0c\u9069\u5408\u9700\u8981\u9ad8\u6027\u80fd\u7684\u61c9\u7528\u3002<\/li>\n<li><strong>Memcached\uff1a<\/strong>\u4e00\u7a2e\u5206\u4f48\u5f0f\u5167\u5b58\u5c0d\u8c61\u5feb\u53d6\u7cfb\u7d71\uff0c\u9069\u5408\u5927\u578b\u61c9\u7528\u3002<\/li>\n<\/ul>\n<h2 id=\"%e5%a6%82%e4%bd%95%e5%9c%a8-thinkphp-%e4%b8%ad%e5%af%a6%e7%8f%be%e6%95%b8%e6%93%9a%e5%ba%ab%e5%bf%ab%e5%8f%96-shbOMteZhb\">\u5982\u4f55\u5728 ThinkPHP \u4e2d\u5be6\u73fe\u6578\u64da\u5eab\u5feb\u53d6<\/h2>\n<p>\u5728 ThinkPHP \u4e2d\u5be6\u73fe\u6578\u64da\u5eab\u5feb\u53d6\u76f8\u5c0d\u7c21\u55ae\u3002\u4ee5\u4e0b\u662f\u4e00\u500b\u57fa\u672c\u7684\u793a\u4f8b\uff0c\u5c55\u793a\u5982\u4f55\u4f7f\u7528\u5feb\u53d6\u4f86\u512a\u5316\u6578\u64da\u5eab\u67e5\u8a62\uff1a<\/p>\n<pre><code>\nuse thinkCache;\n\n\/\/ \u8a2d\u7f6e\u5feb\u53d6\nCache::set('cache_key', $data, 3600); \/\/ 3600\u79d2\u5f8c\u904e\u671f\n\n\/\/ \u7372\u53d6\u5feb\u53d6\n$data = Cache::get('cache_key');\n\nif (!$data) {\n    \/\/ \u5982\u679c\u5feb\u53d6\u4e0d\u5b58\u5728\uff0c\u5f9e\u6578\u64da\u5eab\u67e5\u8a62\n    $data = Db::table('users')-&gt;select();\n    \/\/ \u4e26\u5c07\u7d50\u679c\u5b58\u5165\u5feb\u53d6\n    Cache::set('cache_key', $data, 3600);\n}\n<\/code><\/pre>\n<p>\u5728\u9019\u500b\u793a\u4f8b\u4e2d\uff0c\u6211\u5011\u9996\u5148\u5617\u8a66\u5f9e\u5feb\u53d6\u4e2d\u7372\u53d6\u6578\u64da\u3002\u5982\u679c\u5feb\u53d6\u4e0d\u5b58\u5728\uff0c\u6211\u5011\u5c31\u5f9e\u6578\u64da\u5eab\u4e2d\u67e5\u8a62\u6578\u64da\uff0c\u7136\u5f8c\u5c07\u7d50\u679c\u5b58\u5165\u5feb\u53d6\u4e2d\u3002\u9019\u6a23\u53ef\u4ee5\u986f\u8457\u6e1b\u5c11\u6578\u64da\u5eab\u7684\u67e5\u8a62\u6b21\u6578\uff0c\u63d0\u9ad8\u7db2\u7ad9\u7684\u97ff\u61c9\u901f\u5ea6\u3002<\/p>\n<h2 id=\"%e5%bf%ab%e5%8f%96%e7%9a%84%e6%9c%80%e4%bd%b3%e5%af%a6%e8%b8%90-shbOMteZhb\">\u5feb\u53d6\u7684\u6700\u4f73\u5be6\u8e10<\/h2>\n<p>\u5728\u4f7f\u7528\u6578\u64da\u5eab\u5feb\u53d6\u6642\uff0c\u6709\u5e7e\u500b\u6700\u4f73\u5be6\u8e10\u9700\u8981\u9075\u5faa\uff1a<\/p>\n<ul>\n<li><strong>\u9078\u64c7\u5408\u9069\u7684\u5feb\u53d6\u9a45\u52d5\uff1a<\/strong>\u6839\u64da\u61c9\u7528\u7684\u9700\u6c42\u9078\u64c7\u5408\u9069\u7684\u5feb\u53d6\u9a45\u52d5\uff0c\u78ba\u4fdd\u6027\u80fd\u6700\u4f73\u3002<\/li>\n<li><strong>\u8a2d\u7f6e\u5408\u7406\u7684\u904e\u671f\u6642\u9593\uff1a<\/strong>\u6839\u64da\u6578\u64da\u7684\u8b8a\u5316\u983b\u7387\u8a2d\u7f6e\u5feb\u53d6\u7684\u904e\u671f\u6642\u9593\uff0c\u907f\u514d\u4f7f\u7528\u904e\u671f\u7684\u6578\u64da\u3002<\/li>\n<li><strong>\u76e3\u63a7\u5feb\u53d6\u547d\u4e2d\u7387\uff1a<\/strong>\u5b9a\u671f\u6aa2\u67e5\u5feb\u53d6\u7684\u547d\u4e2d\u7387\uff0c\u4ee5\u8a55\u4f30\u5feb\u53d6\u7b56\u7565\u7684\u6709\u6548\u6027\u3002<\/li>\n<\/ul>\n<h2 id=\"%e7%b5%90%e8%ab%96-shbOMteZhb\">\u7d50\u8ad6<\/h2>\n<p>\u901a\u904e\u6709\u6548\u5730\u4f7f\u7528 ThinkPHP \u7684\u6578\u64da\u5eab\u5feb\u53d6\u6a5f\u5236\uff0c\u958b\u767c\u8005\u53ef\u4ee5\u986f\u8457\u63d0\u9ad8\u7db2\u7ad9\u7684\u6027\u80fd\u548c\u7528\u6236\u9ad4\u9a57\u3002\u5feb\u53d6\u4e0d\u50c5\u80fd\u6e1b\u5c11\u6578\u64da\u5eab\u7684\u8ca0\u64d4\uff0c\u9084\u80fd\u52a0\u5feb\u6578\u64da\u7684\u8a2a\u554f\u901f\u5ea6\u3002\u96a8\u8457\u7db2\u7ad9\u6d41\u91cf\u7684\u589e\u9577\uff0c\u5408\u7406\u7684\u5feb\u53d6\u7b56\u7565\u5c07\u6210\u70ba\u7dad\u6301\u7db2\u7ad9\u6027\u80fd\u7684\u95dc\u9375\u3002<\/p>\n<p>\u5982\u679c\u60a8\u6b63\u5728\u5c0b\u627e\u9ad8\u6548\u7684 <a href=\"https:\/\/server.hk\">\u9999\u6e2fVPS<\/a> \u89e3\u6c7a\u65b9\u6848\u4f86\u652f\u6301\u60a8\u7684 ThinkPHP \u61c9\u7528\uff0cServer.HK \u63d0\u4f9b\u591a\u7a2e\u9078\u64c7\uff0c\u5e6b\u52a9\u60a8\u512a\u5316\u7db2\u7ad9\u6027\u80fd\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u63d0\u5347\u7db2\u7ad9\u901f\u5ea6\uff0c\u4f7f\u7528 ThinkPHP \u6578\u64da\u5eab\u5feb\u53d6\u6280\u8853\uff0c\u512a\u5316\u6578\u64da\u5b58\u53d6\u6548\u7387\uff0c\u589e\u5f37\u7528\u6236\u9ad4\u9a57\u3002<\/p>\n","protected":false},"author":0,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[101],"tags":[],"class_list":["post-144113","post","type-post","status-publish","format-standard","hentry","category-database"],"_links":{"self":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/144113","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"}],"replies":[{"embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/comments?post=144113"}],"version-history":[{"count":1,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/144113\/revisions"}],"predecessor-version":[{"id":144114,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/144113\/revisions\/144114"}],"wp:attachment":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/media?parent=144113"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/categories?post=144113"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/tags?post=144113"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}