{"id":47429,"date":"2024-12-02T08:49:52","date_gmt":"2024-12-02T00:49:52","guid":{"rendered":"https:\/\/fwq.ai\/blog\/47429\/"},"modified":"2024-12-02T08:49:52","modified_gmt":"2024-12-02T00:49:52","slug":"php-%e9%80%92%e5%bd%92%e5%87%bd%e6%95%b0%e7%9a%84%e5%a0%86%e6%a0%88%e6%ba%a2%e5%87%ba%e9%99%90%e5%88%b6%e4%b8%8e%e9%85%8d%e7%bd%ae","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/47429\/","title":{"rendered":"PHP \u9012\u5f52\u51fd\u6570\u7684\u5806\u6808\u6ea2\u51fa\u9650\u5236\u4e0e\u914d\u7f6e"},"content":{"rendered":"<p><b><\/b> <\/p>\n<h1>PHP \u9012\u5f52\u51fd\u6570\u7684\u5806\u6808\u6ea2\u51fa\u9650\u5236\u4e0e\u914d\u7f6e<\/h1>\n<p>\u5927\u5bb6\u597d\uff0c\u6211\u4eec\u53c8\u89c1\u9762\u4e86\u554a~\u672c\u6587<span style=\"color: #FF6600;, Helvetica, Arial, sans-serif;font-size: 14px;background-color: #FFFFFF\">\u300aPHP \u9012\u5f52\u51fd\u6570\u7684\u5806\u6808\u6ea2\u51fa\u9650\u5236\u4e0e\u914d\u7f6e\u300b<\/span>\u7684\u5185\u5bb9\u4e2d\u5c06\u4f1a\u6d89\u53ca\u5230<span style=\"color: #FF6600;, Helvetica, Arial, sans-serif;font-size: 14px;background-color: #FFFFFF\"><\/span>\u7b49\u7b49\u3002\u5982\u679c\u4f60\u6b63\u5728\u5b66\u4e60<span style=\"color: #FF6600;, Helvetica, Arial, sans-serif;font-size: 14px;background-color: #FFFFFF\">\u6587\u7ae0<\/span>\u76f8\u5173\u77e5\u8bc6\uff0c\u6b22\u8fce\u5173\u6ce8\u6211\uff0c\u4ee5\u540e\u4f1a\u7ed9\u5927\u5bb6\u5e26\u6765\u66f4\u591a<span style=\"color: #FF6600;, Helvetica, Arial, sans-serif;font-size: 14px;background-color: #FFFFFF\">\u6587\u7ae0<\/span>\u76f8\u5173\u6587\u7ae0\uff0c\u5e0c\u671b\u6211\u4eec\u80fd\u4e00\u8d77\u8fdb\u6b65\uff01\u4e0b\u9762\u5c31\u5f00\u59cb\u672c\u6587\u7684\u6b63\u5f0f\u5185\u5bb9~<\/p>\n<p>PHP \u9012\u5f52\u51fd\u6570\u7684\u5806\u6808\u6ea2\u51fa\u9650\u5236\uff1aPHP \u5bf9\u51fd\u6570\u8c03\u7528\u5806\u6808\u7684\u5927\u5c0f\u6709\u9650\u5236\uff0c\u9ed8\u8ba4\u503c\u4e3a 128MB\u3002\u8981\u63d0\u9ad8\u9650\u5236\uff0c\u8bf7\u4fee\u6539 php.ini \u6587\u4ef6\u4e2d\u7684 memory_limit \u8bbe\u7f6e\u3002\u4e3a\u4e86\u907f\u514d\u5d4c\u5957\u9012\u5f52\u51fd\u6570\u7684\u5806\u6808\u6ea2\u51fa\uff0c\u8bf7\u8c28\u614e\u4f7f\u7528\u9012\u5f52\uff0c\u5e76\u9002\u5f53\u589e\u52a0\u5806\u6808\u6ea2\u51fa\u9650\u5236\u3002<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.17golang.com\/uploads\/20241026\/1729917877671c73b5c730b.jpg\" class=\"aligncenter\" title=\"PHP \u9012\u5f52\u51fd\u6570\u7684\u5806\u6808\u6ea2\u51fa\u9650\u5236\u4e0e\u914d\u7f6e\u63d2\u56fe\" alt=\"PHP \u9012\u5f52\u51fd\u6570\u7684\u5806\u6808\u6ea2\u51fa\u9650\u5236\u4e0e\u914d\u7f6e\u63d2\u56fe\" \/><\/p>\n<p><strong>PHP \u9012\u5f52\u51fd\u6570\u7684\u5806\u6808\u6ea2\u51fa\u9650\u5236\u4e0e\u914d\u7f6e<\/strong><\/p>\n<p><strong>\u7b80\u4ecb<\/strong><\/p>\n<p>\u9012\u5f52\u51fd\u6570\u662f\u4e00\u79cd\u5728\u51fd\u6570\u5185\u90e8\u8c03\u7528\u81ea\u8eab\u7684\u51fd\u6570\u3002\u5f53\u9012\u5f52\u51fd\u6570\u7684\u8c03\u7528\u6b21\u6570\u8fc7\u591a\u65f6\uff0c\u53ef\u80fd\u4f1a\u5bfc\u81f4\u5806\u6808\u6ea2\u51fa\u9519\u8bef\uff0c\u8fd9\u662f\u56e0\u4e3a PHP \u4e2d\u7684\u51fd\u6570\u8c03\u7528\u662f\u901a\u8fc7\u5806\u6808\u5b9e\u73b0\u7684\u3002\u5806\u6808\u662f\u4e00\u79cd\u6570\u636e\u7ed3\u6784\uff0c\u5b83\u4ee5\u6700\u540e\u8fdb\u5148\u51fa\u7684 (LIFO) \u65b9\u5f0f\u5b58\u50a8\u51fd\u6570\u8c03\u7528\u3002<\/p>\n<p><strong>\u5806\u6808\u6ea2\u51fa\u9650\u5236<\/strong><\/p>\n<p>PHP \u5bf9\u51fd\u6570\u8c03\u7528\u5806\u6808\u7684\u5927\u5c0f\u8bbe\u7f6e\u4e86\u4e00\u4e2a\u9ed8\u8ba4\u9650\u5236\u3002\u8fd9\u4e2a\u9650\u5236\u662f php.ini \u914d\u7f6e\u6587\u4ef6\u4e2d <code>memory_limit<\/code> \u8bbe\u7f6e\u7684\u4e00\u90e8\u5206\u3002\u9ed8\u8ba4\u60c5\u51b5\u4e0b\uff0c<code>memory_limit<\/code> \u9650\u5236\u4e3a 128MB\uff0c\u5176\u4e2d\u5305\u62ec\u5806\u6808\u5927\u5c0f\u3002<\/p>\n<p><strong>\u914d\u7f6e\u5806\u6808\u6ea2\u51fa\u9650\u5236<\/strong><\/p>\n<p>\u8981\u589e\u52a0\u5806\u6808\u6ea2\u51fa\u9650\u5236\uff0c\u53ef\u4ee5\u4fee\u6539 php.ini \u914d\u7f6e\u6587\u4ef6\u4e2d\u7684\u4ee5\u4e0b\u8bbe\u7f6e\uff1a<\/p>\n<pre>memory_limit = 256M<\/pre>\n<p>\u8fd9\u4f1a\u5c06\u5806\u6808\u5927\u5c0f\u589e\u52a0\u5230 256MB\u3002<\/p>\n<p><strong>\u5b9e\u6218\u6848\u4f8b<\/strong><\/p>\n<p>\u4ee5\u4e0b\u662f\u4e00\u4e2a\u8ba1\u7b97\u9636\u4e58\u7684\u9012\u5f52\u51fd\u6570\u7684\u793a\u4f8b\uff1a<\/p>\n<pre>function factorial($n) {\n    if ($n == 0) {\n        return 1;\n    } else {\n        return $n * factorial($n - 1);\n    }\n}<\/pre>\n<p>\u5982\u679c\u6211\u4eec\u5c06\u6b64\u51fd\u6570\u5e94\u7528\u4e8e\u4e00\u4e2a\u8f83\u5927\u7684\u6570\u5b57\uff08\u4f8b\u5982 10000\uff09\uff0c\u5219\u5b83\u5c06\u5bfc\u81f4\u5806\u6808\u6ea2\u51fa\u9519\u8bef\u3002\u4e3a\u4e86\u907f\u514d\u8fd9\u79cd\u60c5\u51b5\uff0c\u6211\u4eec\u53ef\u4ee5\u589e\u52a0\u5806\u6808\u6ea2\u51fa\u9650\u5236\uff0c\u5982\u4e0b\u6240\u793a\uff1a<\/p>\n<pre>ini_set('memory_limit', '512M');\n$result = factorial(10000);<\/pre>\n<p>\u73b0\u5728\uff0c\u51fd\u6570\u5e94\u8be5\u53ef\u4ee5\u6b63\u5e38\u8ba1\u7b97 10000 \u7684\u9636\u4e58\u800c\u4e0d\u5bfc\u81f4\u5806\u6808\u6ea2\u51fa\u9519\u8bef\u3002<\/p>\n<p><strong>\u6ce8\u610f\uff1a<\/strong><\/p>\n<ul>\n<li>\u589e\u52a0\u5806\u6808\u6ea2\u51fa\u9650\u5236\u4f1a\u589e\u52a0\u5185\u5b58\u6d88\u8017\u3002<\/li>\n<li>\u5bf9\u4e8e\u5d4c\u5957\u8f83\u6df1\u7684\u9012\u5f52\u51fd\u6570\uff0c\u5373\u4f7f\u589e\u52a0\u5806\u6808\u6ea2\u51fa\u9650\u5236\u4e5f\u53ef\u80fd\u65e0\u6cd5\u9632\u6b62\u5806\u6808\u6ea2\u51fa\u3002<\/li>\n<li>\u5e94\u8be5\u4ed4\u7ec6\u8003\u8651\u9012\u5f52\u51fd\u6570\u7684\u4f7f\u7528\u60c5\u51b5\uff0c\u5e76\u907f\u514d\u65e0\u9650\u9012\u5f52\u3002<\/li>\n<\/ul>\n<p>\u597d\u4e86\uff0c\u672c\u6587\u5230\u6b64\u7ed3\u675f\uff0c\u5e26\u5927\u5bb6\u4e86\u89e3\u4e86\u300aPHP \u9012\u5f52\u51fd\u6570\u7684\u5806\u6808\u6ea2\u51fa\u9650\u5236\u4e0e\u914d\u7f6e\u300b\uff0c\u5e0c\u671b\u672c\u6587\u5bf9\u4f60\u6709\u6240\u5e2e\u52a9\uff01\u5173\u6ce8\u7c73\u4e91\u516c\u4f17\u53f7\uff0c\u7ed9\u5927\u5bb6\u5206\u4eab\u66f4\u591a\u6587\u7ae0\u77e5\u8bc6\uff01<\/p>\n","protected":false},"excerpt":{"rendered":"<p>PHP \u9012\u5f52\u51fd\u6570\u7684\u5806\u6808\u6ea2\u51fa\u9650\u5236\u4e0e\u914d\u7f6e \u5927\u5bb6\u597d\uff0c\u6211\u4eec\u53c8\u89c1\u9762\u4e86\u554a~\u672c\u6587\u300aPHP \u9012\u5f52\u51fd\u6570\u7684\u5806\u6808\u6ea2\u51fa\u9650\u5236\u4e0e\u914d\u7f6e\u300b\u7684\u5185\u5bb9\u4e2d\u5c06\u4f1a\u6d89\u53ca\u5230\u7b49\u7b49\u3002\u5982\u679c\u4f60\u6b63\u5728\u5b66\u4e60\u6587\u7ae0\u76f8\u5173\u77e5\u8bc6\uff0c\u6b22\u8fce\u5173\u6ce8\u6211\uff0c\u4ee5\u540e\u4f1a\u7ed9\u5927\u5bb6\u5e26\u6765\u66f4\u591a\u6587\u7ae0\u76f8\u5173\u6587\u7ae0\uff0c\u5e0c\u671b\u6211\u4eec\u80fd\u4e00\u8d77\u8fdb\u6b65\uff01\u4e0b\u9762\u5c31\u5f00\u59cb\u672c\u6587\u7684\u6b63\u5f0f\u5185\u5bb9~ PHP \u9012\u5f52\u51fd\u6570\u7684\u5806\u6808\u6ea2\u51fa\u9650\u5236\uff1aPHP \u5bf9\u51fd\u6570\u8c03\u7528\u5806\u6808\u7684\u5927\u5c0f\u6709\u9650\u5236\uff0c\u9ed8\u8ba4\u503c\u4e3a 128MB\u3002\u8981\u63d0\u9ad8\u9650\u5236\uff0c\u8bf7\u4fee\u6539 php.ini \u6587\u4ef6\u4e2d\u7684 memory_limit \u8bbe\u7f6e\u3002\u4e3a\u4e86\u907f\u514d\u5d4c\u5957\u9012\u5f52\u51fd\u6570\u7684\u5806\u6808\u6ea2\u51fa\uff0c\u8bf7\u8c28\u614e\u4f7f\u7528\u9012\u5f52\uff0c\u5e76\u9002\u5f53\u589e\u52a0\u5806\u6808\u6ea2\u51fa\u9650\u5236\u3002 PHP \u9012\u5f52\u51fd\u6570\u7684\u5806\u6808\u6ea2\u51fa\u9650\u5236\u4e0e\u914d\u7f6e \u7b80\u4ecb \u9012\u5f52\u51fd\u6570\u662f\u4e00\u79cd\u5728\u51fd\u6570\u5185\u90e8\u8c03\u7528\u81ea\u8eab\u7684\u51fd\u6570\u3002\u5f53\u9012\u5f52\u51fd\u6570\u7684\u8c03\u7528\u6b21\u6570\u8fc7\u591a\u65f6\uff0c\u53ef\u80fd\u4f1a\u5bfc\u81f4\u5806\u6808\u6ea2\u51fa\u9519\u8bef\uff0c\u8fd9\u662f\u56e0\u4e3a PHP \u4e2d\u7684\u51fd\u6570\u8c03\u7528\u662f\u901a\u8fc7\u5806\u6808\u5b9e\u73b0\u7684\u3002\u5806\u6808\u662f\u4e00\u79cd\u6570\u636e\u7ed3\u6784\uff0c\u5b83\u4ee5\u6700\u540e\u8fdb\u5148\u51fa\u7684 (LIFO) \u65b9\u5f0f\u5b58\u50a8\u51fd\u6570\u8c03\u7528\u3002 \u5806\u6808\u6ea2\u51fa\u9650\u5236 PHP \u5bf9\u51fd\u6570\u8c03\u7528\u5806\u6808\u7684\u5927\u5c0f\u8bbe\u7f6e\u4e86\u4e00\u4e2a\u9ed8\u8ba4\u9650\u5236\u3002\u8fd9\u4e2a\u9650\u5236\u662f php.ini \u914d\u7f6e\u6587\u4ef6\u4e2d memory_limit \u8bbe\u7f6e\u7684\u4e00\u90e8\u5206\u3002\u9ed8\u8ba4\u60c5\u51b5\u4e0b\uff0cmemory_limit \u9650\u5236\u4e3a 128MB\uff0c\u5176\u4e2d\u5305\u62ec\u5806\u6808\u5927\u5c0f\u3002 \u914d\u7f6e\u5806\u6808\u6ea2\u51fa\u9650\u5236 \u8981\u589e\u52a0\u5806\u6808\u6ea2\u51fa\u9650\u5236\uff0c\u53ef\u4ee5\u4fee\u6539 php.ini \u914d\u7f6e\u6587\u4ef6\u4e2d\u7684\u4ee5\u4e0b\u8bbe\u7f6e\uff1a memory_limit = 256M \u8fd9\u4f1a\u5c06\u5806\u6808\u5927\u5c0f\u589e\u52a0\u5230 256MB\u3002 \u5b9e\u6218\u6848\u4f8b \u4ee5\u4e0b\u662f\u4e00\u4e2a\u8ba1\u7b97\u9636\u4e58\u7684\u9012\u5f52\u51fd\u6570\u7684\u793a\u4f8b\uff1a function factorial($n) { if ($n == 0) { return 1; } else { return $n [&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-47429","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/47429","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=47429"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/47429\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=47429"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=47429"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=47429"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}