{"id":46528,"date":"2024-12-02T16:06:46","date_gmt":"2024-12-02T08:06:46","guid":{"rendered":"https:\/\/fwq.ai\/blog\/46528\/"},"modified":"2024-12-02T16:06:46","modified_gmt":"2024-12-02T08:06:46","slug":"php%e5%87%bd%e6%95%b0%e6%97%a5%e5%bf%97%e8%ae%b0%e5%bd%95%e8%be%93%e5%87%ba%e9%97%ae%e9%a2%98%e8%a7%a3%e7%ad%94","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/46528\/","title":{"rendered":"php\u51fd\u6570\u65e5\u5fd7\u8bb0\u5f55\u8f93\u51fa\u95ee\u9898\u89e3\u7b54"},"content":{"rendered":"<p><b><\/b> <\/p>\n<h1>php\u51fd\u6570\u65e5\u5fd7\u8bb0\u5f55\u8f93\u51fa\u95ee\u9898\u89e3\u7b54<\/h1>\n<p><span style=\"font-size: 15px\">\u5b66\u4e60\u77e5\u8bc6\u8981\u5584\u4e8e\u601d\u8003\uff0c\u601d\u8003\uff0c\u518d\u601d\u8003\uff01\u4eca\u5929\u7c73\u4e91\u5c0f\u7f16\u5c31\u7ed9\u5927\u5bb6\u5e26\u6765<span style=\"color: #FF6600;, Helvetica, Arial, sans-serif;font-size: 14px;background-color: #FFFFFF\">\u300aphp\u51fd\u6570\u65e5\u5fd7\u8bb0\u5f55\u8f93\u51fa\u95ee\u9898\u89e3\u7b54\u300b<\/span>\uff0c\u4ee5\u4e0b\u5185\u5bb9\u4e3b\u8981\u5305\u542b<span style=\"color: #FF6600;, Helvetica, Arial, sans-serif;font-size: 14px;background-color: #FFFFFF\"><\/span>\u7b49\u77e5\u8bc6\u70b9\uff0c\u5982\u679c\u4f60\u6b63\u5728\u5b66\u4e60\u6216\u51c6\u5907\u5b66\u4e60<span style=\"color: #FF6600;, Helvetica, Arial, sans-serif;font-size: 14px;background-color: #FFFFFF\">\u6587\u7ae0<\/span>\uff0c\u5c31\u90fd\u4e0d\u8981\u9519\u8fc7\u672c\u6587\u5566~\u8ba9\u6211\u4eec\u4e00\u8d77\u6765\u770b\u770b\u5427\uff0c\u80fd\u5e2e\u52a9\u5230\u4f60\u5c31\u66f4\u597d\u4e86\uff01<\/span><\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.17golang.com\/uploads\/20241012\/1728725335670a41576f13b.jpg\" class=\"aligncenter\" title=\"php\u51fd\u6570\u65e5\u5fd7\u8bb0\u5f55\u8f93\u51fa\u95ee\u9898\u89e3\u7b54\u63d2\u56fe\" alt=\"php\u51fd\u6570\u65e5\u5fd7\u8bb0\u5f55\u8f93\u51fa\u95ee\u9898\u89e3\u7b54\u63d2\u56fe\" \/><\/p>\n<p><strong>PHP \u51fd\u6570\u65e5\u5fd7\u8bb0\u5f55\u8f93\u51fa\u95ee\u9898\u89e3\u7b54<\/strong><\/p>\n<p><strong>1. \u65e5\u5fd7\u8bb0\u5f55\u914d\u7f6e\u65e0\u6548<\/strong><\/p>\n<pre>&lt;?php\n\/\/ \u914d\u7f6e\u6587\u4ef6\u65e0\u6548\u7684\u793a\u4f8b\nerror_reporting(E_ALL);\nini_set('display_errors', 1);\n\n\/\/ \u521b\u5efa\u4e00\u4e2a\u4e0d\u5b58\u5728\u7684\u76ee\u5f55\n$dir = '\/nonexistent\/path\/to\/logs';\nini_set('error_log', $dir . '\/errors.log');<\/pre>\n<p><strong>\u89e3\u51b3\u65b9\u6848\uff1a<\/strong>\u786e\u4fdd\u65e5\u5fd7\u914d\u7f6e\u6b63\u786e\uff0c\u5e76\u4e14\u8def\u5f84\u6709\u6548\u3002<\/p>\n<p><strong>2. \u6743\u9650\u4e0d\u8db3<\/strong><\/p>\n<pre>&lt;?php\n\/\/ \u6587\u4ef6\u6743\u9650\u9519\u8bef\u7684\u793a\u4f8b\nerror_reporting(E_ALL);\nini_set('display_errors', 1);\n\n\/\/ \u5c06\u9519\u8bef\u65e5\u5fd7\u5199\u5165\u4e00\u4e2a\u53d7\u9650\u8bbf\u95ee\u76ee\u5f55\n$dir = '\/var\/log\/web';\nif (!is_dir($dir)) {\n    mkdir($dir);\n}\nchmod($dir, 0700);\n\nini_set('error_log', $dir . '\/errors.log');<\/pre>\n<p><strong>\u89e3\u51b3\u65b9\u6848\uff1a<\/strong>\u786e\u4fdd web \u670d\u52a1\u5668\u6216\u5176\u4ed6\u8fdb\u7a0b\u6709\u6743\u9650\u5199\u5165\u65e5\u5fd7\u6587\u4ef6\u3002<\/p>\n<p><strong>3. \u8bed\u6cd5\u9519\u8bef\u963b\u788d\u65e5\u5fd7\u8bb0\u5f55<\/strong><\/p>\n<pre>&lt;?php\n\/\/ \u8bed\u6cd5\u9519\u8bef\u7684\u793a\u4f8b\nerror_reporting(E_ALL);\nini_set('display_errors', 1);\n\n\/\/ \u6709\u610f\u5236\u9020\u4e00\u4e2a\u8bed\u6cd5\u9519\u8bef\necho 'This is a test'<\/pre>\n<p><strong>\u89e3\u51b3\u65b9\u6848\uff1a<\/strong>\u786e\u4fdd\u4ee3\u7801\u4e2d\u6ca1\u6709\u8bed\u6cd5\u9519\u8bef\uff0c\u56e0\u4e3a\u5b83\u4eec\u4f1a\u963b\u6b62\u6267\u884c\u65e5\u5fd7\u8bb0\u5f55\u3002<\/p>\n<p><strong>4. \u4f7f\u7528\u9519\u8bef\u7684\u51fd\u6570<\/strong><\/p>\n<pre>&lt;?php\n\/\/ \u4f7f\u7528\u9519\u8bef\u7684\u51fd\u6570\u793a\u4f8b\nerror_reporting(E_ALL);\nini_set('display_errors', 1);\n\n\/\/ \u4f7f\u7528 `trigger_error()` \u4ee3\u66ff `error_log()`\ntrigger_error('This is a test message', E_USER_ERROR);<\/pre>\n<p><strong>\u89e3\u51b3\u65b9\u6848\uff1a<\/strong>\u786e\u4fdd\u4f7f\u7528\u6b63\u786e\u7684\u65e5\u5fd7\u8bb0\u5f55\u51fd\u6570\uff0c\u4f8b\u5982 <code>error_log()<\/code> \u6216 <code>syslog()<\/code>\u3002<\/p>\n<p><strong>\u5b9e\u6218\u6848\u4f8b\uff1a<\/strong><\/p>\n<pre>&lt;?php\n\/\/ \u6b63\u786e\u7684\u65e5\u5fd7\u8bb0\u5f55\u793a\u4f8b\nerror_reporting(E_ALL);\nini_set('display_errors', 1);\n\n\/\/ \u914d\u7f6e\u65e5\u5fd7\u6587\u4ef6\u8def\u5f84\u548c\u6743\u9650\n$dir = '\/var\/log\/web';\nif (!is_dir($dir)) {\n    mkdir($dir, 0755, true);\n}\n\nini_set('error_log', $dir . '\/errors.log');\n\n\/\/ \u4f7f\u7528\u6b63\u786e\u7684\u51fd\u6570\u8bb0\u5f55\u9519\u8bef\u6d88\u606f\nerror_log('This is a test message');<\/pre>\n<p>\u4eca\u5929\u5e26\u5927\u5bb6\u4e86\u89e3\u4e86\u7684\u76f8\u5173\u77e5\u8bc6\uff0c\u5e0c\u671b\u5bf9\u4f60\u6709\u6240\u5e2e\u52a9\uff1b\u5173\u4e8e\u6587\u7ae0\u7684\u6280\u672f\u77e5\u8bc6\u6211\u4eec\u4f1a\u4e00\u70b9\u70b9\u6df1\u5165\u4ecb\u7ecd\uff0c\u6b22\u8fce\u5927\u5bb6\u5173\u6ce8\u7c73\u4e91\u516c\u4f17\u53f7\uff0c\u4e00\u8d77\u5b66\u4e60\u7f16\u7a0b~<\/p>\n","protected":false},"excerpt":{"rendered":"<p>php\u51fd\u6570\u65e5\u5fd7\u8bb0\u5f55\u8f93\u51fa\u95ee\u9898\u89e3\u7b54 \u5b66\u4e60\u77e5\u8bc6\u8981\u5584\u4e8e\u601d\u8003\uff0c\u601d\u8003\uff0c\u518d\u601d\u8003\uff01\u4eca\u5929\u7c73\u4e91\u5c0f\u7f16\u5c31\u7ed9\u5927\u5bb6\u5e26\u6765\u300aphp\u51fd\u6570\u65e5\u5fd7\u8bb0\u5f55\u8f93\u51fa\u95ee\u9898\u89e3\u7b54\u300b\uff0c\u4ee5\u4e0b\u5185\u5bb9\u4e3b\u8981\u5305\u542b\u7b49\u77e5\u8bc6\u70b9\uff0c\u5982\u679c\u4f60\u6b63\u5728\u5b66\u4e60\u6216\u51c6\u5907\u5b66\u4e60\u6587\u7ae0\uff0c\u5c31\u90fd\u4e0d\u8981\u9519\u8fc7\u672c\u6587\u5566~\u8ba9\u6211\u4eec\u4e00\u8d77\u6765\u770b\u770b\u5427\uff0c\u80fd\u5e2e\u52a9\u5230\u4f60\u5c31\u66f4\u597d\u4e86\uff01 PHP \u51fd\u6570\u65e5\u5fd7\u8bb0\u5f55\u8f93\u51fa\u95ee\u9898\u89e3\u7b54 1. \u65e5\u5fd7\u8bb0\u5f55\u914d\u7f6e\u65e0\u6548 &lt;?php \/\/ \u914d\u7f6e\u6587\u4ef6\u65e0\u6548\u7684\u793a\u4f8b error_reporting(E_ALL); ini_set(&#8216;display_errors&#8217;, 1); \/\/ \u521b\u5efa\u4e00\u4e2a\u4e0d\u5b58\u5728\u7684\u76ee\u5f55 $dir = &#8216;\/nonexistent\/path\/to\/logs&#8217;; ini_set(&#8216;error_log&#8217;, $dir . &#8216;\/errors.log&#8217;); \u89e3\u51b3\u65b9\u6848\uff1a\u786e\u4fdd\u65e5\u5fd7\u914d\u7f6e\u6b63\u786e\uff0c\u5e76\u4e14\u8def\u5f84\u6709\u6548\u3002 2. \u6743\u9650\u4e0d\u8db3 &lt;?php \/\/ \u6587\u4ef6\u6743\u9650\u9519\u8bef\u7684\u793a\u4f8b error_reporting(E_ALL); ini_set(&#8216;display_errors&#8217;, 1); \/\/ \u5c06\u9519\u8bef\u65e5\u5fd7\u5199\u5165\u4e00\u4e2a\u53d7\u9650\u8bbf\u95ee\u76ee\u5f55 $dir = &#8216;\/var\/log\/web&#8217;; if (!is_dir($dir)) { mkdir($dir); } chmod($dir, 0700); ini_set(&#8216;error_log&#8217;, $dir . &#8216;\/errors.log&#8217;); \u89e3\u51b3\u65b9\u6848\uff1a\u786e\u4fdd web \u670d\u52a1\u5668\u6216\u5176\u4ed6\u8fdb\u7a0b\u6709\u6743\u9650\u5199\u5165\u65e5\u5fd7\u6587\u4ef6\u3002 3. \u8bed\u6cd5\u9519\u8bef\u963b\u788d\u65e5\u5fd7\u8bb0\u5f55 &lt;?php \/\/ \u8bed\u6cd5\u9519\u8bef\u7684\u793a\u4f8b error_reporting(E_ALL); [&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-46528","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/46528","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=46528"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/46528\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=46528"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=46528"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=46528"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}