{"id":47589,"date":"2024-12-02T12:48:25","date_gmt":"2024-12-02T04:48:25","guid":{"rendered":"https:\/\/fwq.ai\/blog\/47589\/"},"modified":"2024-12-02T12:48:25","modified_gmt":"2024-12-02T04:48:25","slug":"php%e5%87%bd%e6%95%b0%e6%97%a5%e5%bf%97%e8%ae%b0%e5%bd%95%e6%97%a5%e5%bf%97%e7%ae%a1%e7%90%86%e9%97%ae%e9%a2%98%e8%a7%a3%e7%ad%94","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/47589\/","title":{"rendered":"php\u51fd\u6570\u65e5\u5fd7\u8bb0\u5f55\u65e5\u5fd7\u7ba1\u7406\u95ee\u9898\u89e3\u7b54"},"content":{"rendered":"<p><b><\/b> <\/p>\n<h1>php\u51fd\u6570\u65e5\u5fd7\u8bb0\u5f55\u65e5\u5fd7\u7ba1\u7406\u95ee\u9898\u89e3\u7b54<\/h1>\n<p>\u54c8\u55bd\uff01\u5927\u5bb6\u597d\uff0c\u5f88\u9ad8\u5174\u53c8\u89c1\u9762\u4e86\uff0c\u6211\u662f\u7c73\u4e91\u7684\u4e00\u540d\u4f5c\u8005\uff0c\u4eca\u5929\u7531\u6211\u7ed9\u5927\u5bb6\u5e26\u6765\u4e00\u7bc7<span style=\"color: #FF6600;, Helvetica, Arial, sans-serif;font-size: 14px;background-color: #FFFFFF\">\u300aphp\u51fd\u6570\u65e5\u5fd7\u8bb0\u5f55\u65e5\u5fd7\u7ba1\u7406\u95ee\u9898\u89e3\u7b54\u300b<\/span>\uff0c\u672c\u6587\u4e3b\u8981\u4f1a\u8bb2\u5230<span style=\"color: #FF6600;, Helvetica, Arial, sans-serif;font-size: 14px;background-color: #FFFFFF\"><\/span>\u7b49\u7b49\u77e5\u8bc6\u70b9\uff0c\u5e0c\u671b\u5927\u5bb6\u4e00\u8d77\u5b66\u4e60\u8fdb\u6b65\uff0c\u4e5f\u6b22\u8fce\u5927\u5bb6\u5173\u6ce8\u3001\u70b9\u8d5e\u3001\u6536\u85cf\u3001\u8f6c\u53d1! \u4e0b\u9762\u5c31\u4e00\u8d77\u6765\u770b\u770b\u5427\uff01<\/p>\n<p>PHP \u4e2d\u7684\u65e5\u5fd7\u8bb0\u5f55\u63d0\u4f9b\u4e86\u8bb0\u5f55\u5e94\u7528\u7a0b\u5e8f\u884c\u4e3a\u3001\u8c03\u8bd5\u9519\u8bef\u548c\u8bc6\u522b\u95ee\u9898\u7684\u529f\u80fd\uff0c\u53ef\u4f7f\u7528\u5185\u7f6e\u51fd\u6570\u8f7b\u677e\u5b9e\u73b0\u3002error_log() \u7528\u4e8e\u8bb0\u5f55\u9519\u8bef\u6d88\u606f\uff0clog() \u5219\u5141\u8bb8\u4f7f\u7528\u81ea\u5b9a\u4e49\u65e5\u5fd7\u7ea7\u522b\u8bb0\u5f55\u4efb\u610f\u6d88\u606f\uff0csyslog() \u5219\u4f7f\u7528\u7cfb\u7edf\u65e5\u5fd7\u5b88\u62a4\u8fdb\u7a0b\u8bb0\u5f55\u6d88\u606f\u3002\u5e38\u89c1\u7684\u65e5\u5fd7\u8bb0\u5f55\u95ee\u9898\u5305\u62ec\uff1a\u5c06\u65e5\u5fd7\u8bb0\u5f55\u5230\u7279\u5b9a\u6587\u4ef6\u3001\u8bbe\u7f6e\u81ea\u5b9a\u4e49\u65e5\u5fd7\u7ea7\u522b\u548c\u4f7f\u7528\u4e0d\u540c\u7684\u65e5\u5fd7\u7ea7\u522b\u3002\u8fd9\u4e9b\u95ee\u9898\u53ef\u4ee5\u901a\u8fc7\u4f7f\u7528 error_log() \u51fd\u6570\u5e76\u6307\u5b9a destination \u53c2\u6570\u3001\u4f7f\u7528 log() \u51fd\u6570\u5e76\u6307\u5b9a level \u53c2\u6570\uff0c\u4ee5\u53ca\u4f7f\u7528\u9884\u5b9a\u4e49\u7684 PSR-3 \u65e5\u5fd7\u7ea7\u522b\u6765\u89e3\u51b3\u3002<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.17golang.com\/uploads\/20241026\/1729924709671c8e659d731.jpg\" class=\"aligncenter\" title=\"php\u51fd\u6570\u65e5\u5fd7\u8bb0\u5f55\u65e5\u5fd7\u7ba1\u7406\u95ee\u9898\u89e3\u7b54\u63d2\u56fe\" alt=\"php\u51fd\u6570\u65e5\u5fd7\u8bb0\u5f55\u65e5\u5fd7\u7ba1\u7406\u95ee\u9898\u89e3\u7b54\u63d2\u56fe\" \/><\/p>\n<h2>PHP \u65e5\u5fd7\u8bb0\u5f55\uff1a\u5982\u4f55\u8bb0\u5f55\u548c\u7ba1\u7406\u65e5\u5fd7<\/h2>\n<p><strong>\u524d\u8a00<\/strong><\/p>\n<p>\u5728\u7f16\u5199 PHP \u5e94\u7528\u7a0b\u5e8f\u65f6\uff0c\u65e5\u5fd7\u8bb0\u5f55\u662f\u81f3\u5173\u91cd\u8981\u7684\u3002\u5b83\u5141\u8bb8\u60a8\u8bb0\u5f55\u5e94\u7528\u7a0b\u5e8f\u7684\u884c\u4e3a\u3001\u8c03\u8bd5\u9519\u8bef\u5e76\u8bc6\u522b\u95ee\u9898\u3002\u672c\u6587\u5c06\u6307\u5bfc\u60a8\u4f7f\u7528 PHP \u8bb0\u5f55\u65e5\u5fd7\uff0c\u5e76\u63d0\u4f9b\u89e3\u51b3\u5e38\u89c1\u95ee\u9898\u89e3\u7b54\u7684\u5b9e\u7528\u6848\u4f8b\u3002<\/p>\n<p><strong>PHP \u4e2d\u7684\u65e5\u5fd7\u8bb0\u5f55<\/strong><\/p>\n<p>PHP \u63d0\u4f9b\u4e86\u8bb8\u591a\u5185\u7f6e\u51fd\u6570\u7528\u4e8e\u65e5\u5fd7\u8bb0\u5f55\uff0c\u5305\u62ec\uff1a<\/p>\n<ul>\n<li><code>error_log()<\/code>\uff1a\u8bb0\u5f55\u9519\u8bef\u6d88\u606f\u3002<\/li>\n<li><code>log()<\/code>\uff1a\u8bb0\u5f55\u4efb\u610f\u6d88\u606f\u3002<\/li>\n<li><code>syslog()<\/code>\uff1a\u4f7f\u7528\u7cfb\u7edf\u65e5\u5fd7\u5b88\u62a4\u8fdb\u7a0b\u8bb0\u5f55\u6d88\u606f\u3002<\/li>\n<\/ul>\n<p><strong>\u4f7f\u7528 error_log()<\/strong><\/p>\n<p><code>error_log()<\/code> \u51fd\u6570\u662f\u8bb0\u5f55\u9519\u8bef\u6d88\u606f\u7684\u6700\u5e38\u7528\u65b9\u6cd5\u3002\u5b83\u63a5\u6536\u4e24\u5230\u56db\u4e2a\u53c2\u6570\uff1a<\/p>\n<pre>error_log(message, message_type, destination, extra_headers);<\/pre>\n<ul>\n<li><code>message<\/code>\uff1a\u8981\u8bb0\u5f55\u7684\u6d88\u606f\u3002<\/li>\n<li><code>message_type<\/code>\uff08\u53ef\u9009\uff09\uff1a\u6307\u5b9a\u6d88\u606f\u7684\u7c7b\u578b\u3002\u60a8\u53ef\u4ee5\u5728 PHP \u5e38\u91cf\u4e2d\u627e\u5230\u53ef\u7528\u7684\u7c7b\u578b\uff08\u4f8b\u5982 <code>E_USER_ERROR<\/code>\uff09\u3002<\/li>\n<li><code>destination<\/code>\uff08\u53ef\u9009\uff09\uff1a\u6307\u5b9a\u6d88\u606f\u7684\u76ee\u7684\u5730\u3002\u60a8\u53ef\u4ee5\u4f7f\u7528 <code>FILE_APPEND<\/code> \u5c06\u6d88\u606f\u8ffd\u52a0\u5230\u6587\u4ef6\uff0c\u6216\u4f7f\u7528 <code>syslog<\/code> \u8bb0\u5f55\u5230\u7cfb\u7edf\u65e5\u5fd7\u3002<\/li>\n<li><code>extra_headers<\/code>\uff08\u53ef\u9009\uff09\uff1a\u4e3a\u90ae\u4ef6\u6216 syslog \u6d88\u606f\u6dfb\u52a0\u989d\u5916\u7684\u6807\u9898\u884c\u3002<\/li>\n<\/ul>\n<p><strong>\u4f7f\u7528 log()<\/strong><\/p>\n<p><code>log()<\/code> \u51fd\u6570\u7c7b\u4f3c\u4e8e <code>error_log()<\/code>, \u4f46\u5b83\u5141\u8bb8\u60a8\u6307\u5b9a\u81ea\u5b9a\u4e49\u65e5\u5fd7\u7ea7\u522b\u3002\u5b83\u63a5\u6536\u4e09\u4e2a\u53c2\u6570\uff1a<\/p>\n<pre>log(level, message, destination);<\/pre>\n<ul>\n<li><code>level<\/code>\uff1a\u6307\u5b9a\u6d88\u606f\u7684\u7ea7\u522b\u3002\u60a8\u53ef\u4ee5\u4f7f\u7528 PSR-3 \u65e5\u5fd7\u7ea7\u522b\uff08\u4f8b\u5982 <code>DEBUG<\/code>\u3001<code>INFO<\/code>\u3001<code>WARNING<\/code>\uff09\u3002<\/li>\n<li><code>message<\/code>\uff1a\u8981\u8bb0\u5f55\u7684\u6d88\u606f\u3002<\/li>\n<li><code>destination<\/code>\uff1a\u6307\u5b9a\u6d88\u606f\u7684\u76ee\u7684\u5730\u3002<\/li>\n<\/ul>\n<p><strong>\u4f7f\u7528 syslog()<\/strong><\/p>\n<p><code>syslog()<\/code> \u51fd\u6570\u4f7f\u7528\u7cfb\u7edf\u65e5\u5fd7\u5b88\u62a4\u8fdb\u7a0b\u8bb0\u5f55\u6d88\u606f\u3002\u5b83\u63a5\u6536\u4e09\u4e2a\u53c2\u6570\uff1a<\/p>\n<pre>syslog(priority, message, facility);<\/pre>\n<ul>\n<li><code>priority<\/code>\uff1a\u6307\u5b9a\u6d88\u606f\u7684\u4f18\u5148\u7ea7\u3002<\/li>\n<li><code>message<\/code>\uff1a\u8981\u8bb0\u5f55\u7684\u6d88\u606f\u3002<\/li>\n<li><code>facility<\/code>\uff1a\u6307\u5b9a\u6d88\u606f\u7684\u6765\u6e90\u3002<\/li>\n<\/ul>\n<p><strong>\u5b9e\u7528\u6848\u4f8b<\/strong><\/p>\n<p><strong>\u6848\u4f8b 1\uff1a\u8bb0\u5f55\u9519\u8bef\u6d88\u606f<\/strong><\/p>\n<p>\u4f7f\u7528 <code>error_log()<\/code> \u8bb0\u5f55\u9519\u8bef\u6d88\u606f\uff1a<\/p>\n<pre>&lt;?php\nerror_log('An error occurred', E_USER_ERROR);\n?&gt;<\/pre>\n<p><strong>\u6848\u4f8b 2\uff1a\u8bb0\u5f55\u8c03\u8bd5\u6d88\u606f<\/strong><\/p>\n<p>\u4f7f\u7528 <code>log()<\/code> \u8bb0\u5f55\u8c03\u8bd5\u6d88\u606f\uff1a<\/p>\n<pre>&lt;?php\nlog(LOG_DEBUG, 'Debug message');\n?&gt;<\/pre>\n<p><strong>\u95ee\u9898\u89e3\u7b54<\/strong><\/p>\n<p><strong>\u95ee\u9898\uff1a\u5982\u4f55\u5c06\u65e5\u5fd7\u8bb0\u5f55\u5230\u7279\u5b9a\u6587\u4ef6\uff1f<\/strong><br \/><strong>\u56de\u7b54\uff1a<\/strong>\u4f7f\u7528 <code>error_log()<\/code> \u51fd\u6570\u5e76\u5c06\u5176 <code>destination<\/code> \u53c2\u6570\u8bbe\u7f6e\u4e3a <code>FILE_APPEND<\/code>\u3002<\/p>\n<p><strong>\u95ee\u9898\uff1a\u5982\u4f55\u8bbe\u7f6e\u81ea\u5b9a\u4e49\u65e5\u5fd7\u7ea7\u522b\uff1f<\/strong><br \/><strong>\u56de\u7b54\uff1a<\/strong>\u4f7f\u7528 <code>log()<\/code> \u51fd\u6570\u5e76\u5c06\u5176 <code>level<\/code> \u53c2\u6570\u8bbe\u7f6e\u4e3a\u81ea\u5b9a\u4e49\u7ea7\u522b\u3002<\/p>\n<p><strong>\u95ee\u9898\uff1a\u5982\u4f55\u4f7f\u7528\u4e0d\u540c\u7684\u65e5\u5fd7\u7ea7\u522b\uff1f<\/strong><br \/><strong>\u56de\u7b54\uff1a<\/strong>\u4f7f\u7528 <code>log()<\/code> \u51fd\u6570\u5e76\u5c06\u5176 <code>level<\/code> \u53c2\u6570\u8bbe\u7f6e\u4e3a\u9884\u5b9a\u4e49\u7684 PSR-3 \u65e5\u5fd7\u7ea7\u522b\u3002<\/p>\n<p>\u4ee5\u4e0a\u5c31\u662f\u672c\u6587\u7684\u5168\u90e8\u5185\u5bb9\u4e86\uff0c\u662f\u5426\u6709\u987a\u5229\u5e2e\u52a9\u4f60\u89e3\u51b3\u95ee\u9898\uff1f\u82e5\u662f\u80fd\u7ed9\u4f60\u5e26\u6765\u5b66\u4e60\u4e0a\u7684\u5e2e\u52a9\uff0c\u8bf7\u5927\u5bb6\u591a\u591a\u652f\u6301\u7c73\u4e91\uff01\u66f4\u591a\u5173\u4e8e\u6587\u7ae0\u7684\u76f8\u5173\u77e5\u8bc6\uff0c\u4e5f\u53ef\u5173\u6ce8\u7c73\u4e91\u516c\u4f17\u53f7\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>php\u51fd\u6570\u65e5\u5fd7\u8bb0\u5f55\u65e5\u5fd7\u7ba1\u7406\u95ee\u9898\u89e3\u7b54 \u54c8\u55bd\uff01\u5927\u5bb6\u597d\uff0c\u5f88\u9ad8\u5174\u53c8\u89c1\u9762\u4e86\uff0c\u6211\u662f\u7c73\u4e91\u7684\u4e00\u540d\u4f5c\u8005\uff0c\u4eca\u5929\u7531\u6211\u7ed9\u5927\u5bb6\u5e26\u6765\u4e00\u7bc7\u300aphp\u51fd\u6570\u65e5\u5fd7\u8bb0\u5f55\u65e5\u5fd7\u7ba1\u7406\u95ee\u9898\u89e3\u7b54\u300b\uff0c\u672c\u6587\u4e3b\u8981\u4f1a\u8bb2\u5230\u7b49\u7b49\u77e5\u8bc6\u70b9\uff0c\u5e0c\u671b\u5927\u5bb6\u4e00\u8d77\u5b66\u4e60\u8fdb\u6b65\uff0c\u4e5f\u6b22\u8fce\u5927\u5bb6\u5173\u6ce8\u3001\u70b9\u8d5e\u3001\u6536\u85cf\u3001\u8f6c\u53d1! \u4e0b\u9762\u5c31\u4e00\u8d77\u6765\u770b\u770b\u5427\uff01 PHP \u4e2d\u7684\u65e5\u5fd7\u8bb0\u5f55\u63d0\u4f9b\u4e86\u8bb0\u5f55\u5e94\u7528\u7a0b\u5e8f\u884c\u4e3a\u3001\u8c03\u8bd5\u9519\u8bef\u548c\u8bc6\u522b\u95ee\u9898\u7684\u529f\u80fd\uff0c\u53ef\u4f7f\u7528\u5185\u7f6e\u51fd\u6570\u8f7b\u677e\u5b9e\u73b0\u3002error_log() \u7528\u4e8e\u8bb0\u5f55\u9519\u8bef\u6d88\u606f\uff0clog() \u5219\u5141\u8bb8\u4f7f\u7528\u81ea\u5b9a\u4e49\u65e5\u5fd7\u7ea7\u522b\u8bb0\u5f55\u4efb\u610f\u6d88\u606f\uff0csyslog() \u5219\u4f7f\u7528\u7cfb\u7edf\u65e5\u5fd7\u5b88\u62a4\u8fdb\u7a0b\u8bb0\u5f55\u6d88\u606f\u3002\u5e38\u89c1\u7684\u65e5\u5fd7\u8bb0\u5f55\u95ee\u9898\u5305\u62ec\uff1a\u5c06\u65e5\u5fd7\u8bb0\u5f55\u5230\u7279\u5b9a\u6587\u4ef6\u3001\u8bbe\u7f6e\u81ea\u5b9a\u4e49\u65e5\u5fd7\u7ea7\u522b\u548c\u4f7f\u7528\u4e0d\u540c\u7684\u65e5\u5fd7\u7ea7\u522b\u3002\u8fd9\u4e9b\u95ee\u9898\u53ef\u4ee5\u901a\u8fc7\u4f7f\u7528 error_log() \u51fd\u6570\u5e76\u6307\u5b9a destination \u53c2\u6570\u3001\u4f7f\u7528 log() \u51fd\u6570\u5e76\u6307\u5b9a level \u53c2\u6570\uff0c\u4ee5\u53ca\u4f7f\u7528\u9884\u5b9a\u4e49\u7684 PSR-3 \u65e5\u5fd7\u7ea7\u522b\u6765\u89e3\u51b3\u3002 PHP \u65e5\u5fd7\u8bb0\u5f55\uff1a\u5982\u4f55\u8bb0\u5f55\u548c\u7ba1\u7406\u65e5\u5fd7 \u524d\u8a00 \u5728\u7f16\u5199 PHP \u5e94\u7528\u7a0b\u5e8f\u65f6\uff0c\u65e5\u5fd7\u8bb0\u5f55\u662f\u81f3\u5173\u91cd\u8981\u7684\u3002\u5b83\u5141\u8bb8\u60a8\u8bb0\u5f55\u5e94\u7528\u7a0b\u5e8f\u7684\u884c\u4e3a\u3001\u8c03\u8bd5\u9519\u8bef\u5e76\u8bc6\u522b\u95ee\u9898\u3002\u672c\u6587\u5c06\u6307\u5bfc\u60a8\u4f7f\u7528 PHP \u8bb0\u5f55\u65e5\u5fd7\uff0c\u5e76\u63d0\u4f9b\u89e3\u51b3\u5e38\u89c1\u95ee\u9898\u89e3\u7b54\u7684\u5b9e\u7528\u6848\u4f8b\u3002 PHP \u4e2d\u7684\u65e5\u5fd7\u8bb0\u5f55 PHP \u63d0\u4f9b\u4e86\u8bb8\u591a\u5185\u7f6e\u51fd\u6570\u7528\u4e8e\u65e5\u5fd7\u8bb0\u5f55\uff0c\u5305\u62ec\uff1a error_log()\uff1a\u8bb0\u5f55\u9519\u8bef\u6d88\u606f\u3002 log()\uff1a\u8bb0\u5f55\u4efb\u610f\u6d88\u606f\u3002 syslog()\uff1a\u4f7f\u7528\u7cfb\u7edf\u65e5\u5fd7\u5b88\u62a4\u8fdb\u7a0b\u8bb0\u5f55\u6d88\u606f\u3002 \u4f7f\u7528 error_log() error_log() \u51fd\u6570\u662f\u8bb0\u5f55\u9519\u8bef\u6d88\u606f\u7684\u6700\u5e38\u7528\u65b9\u6cd5\u3002\u5b83\u63a5\u6536\u4e24\u5230\u56db\u4e2a\u53c2\u6570\uff1a error_log(message, message_type, destination, extra_headers); message\uff1a\u8981\u8bb0\u5f55\u7684\u6d88\u606f\u3002 message_type\uff08\u53ef\u9009\uff09\uff1a\u6307\u5b9a\u6d88\u606f\u7684\u7c7b\u578b\u3002\u60a8\u53ef\u4ee5\u5728 PHP \u5e38\u91cf\u4e2d\u627e\u5230\u53ef\u7528\u7684\u7c7b\u578b\uff08\u4f8b\u5982 E_USER_ERROR\uff09\u3002 destination\uff08\u53ef\u9009\uff09\uff1a\u6307\u5b9a\u6d88\u606f\u7684\u76ee\u7684\u5730\u3002\u60a8\u53ef\u4ee5\u4f7f\u7528 FILE_APPEND \u5c06\u6d88\u606f\u8ffd\u52a0\u5230\u6587\u4ef6\uff0c\u6216\u4f7f\u7528 syslog \u8bb0\u5f55\u5230\u7cfb\u7edf\u65e5\u5fd7\u3002 extra_headers\uff08\u53ef\u9009\uff09\uff1a\u4e3a\u90ae\u4ef6\u6216 syslog \u6d88\u606f\u6dfb\u52a0\u989d\u5916\u7684\u6807\u9898\u884c\u3002 \u4f7f\u7528 [&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-47589","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/47589","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=47589"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/47589\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=47589"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=47589"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=47589"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}