{"id":48121,"date":"2024-12-02T08:49:17","date_gmt":"2024-12-02T00:49:17","guid":{"rendered":"https:\/\/fwq.ai\/blog\/48121\/"},"modified":"2024-12-02T08:49:17","modified_gmt":"2024-12-02T00:49:17","slug":"%e5%a6%82%e4%bd%95%e4%bd%bf%e7%94%a8-php-%e5%87%bd%e6%95%b0%e8%ae%b0%e5%bd%95%e5%bc%82%e6%ad%a5%e6%97%a5%e5%bf%97%ef%bc%9f","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/48121\/","title":{"rendered":"\u5982\u4f55\u4f7f\u7528 PHP \u51fd\u6570\u8bb0\u5f55\u5f02\u6b65\u65e5\u5fd7\uff1f"},"content":{"rendered":"<p><b><\/b> <\/p>\n<h1>\u5982\u4f55\u4f7f\u7528 PHP \u51fd\u6570\u8bb0\u5f55\u5f02\u6b65\u65e5\u5fd7\uff1f<\/h1>\n<p>\u7f16\u7a0b\u5e76\u4e0d\u662f\u4e00\u4e2a\u673a\u68b0\u6027\u7684\u5de5\u4f5c\uff0c\u800c\u662f\u9700\u8981\u6709\u601d\u8003\uff0c\u6709\u521b\u65b0\u7684\u5de5\u4f5c\uff0c\u8bed\u6cd5\u662f\u56fa\u5b9a\u7684\uff0c\u4f46\u89e3\u51b3\u95ee\u9898\u7684\u601d\u8def\u5219\u662f\u4f9d\u9760\u4eba\u7684\u601d\u7ef4\uff0c\u8fd9\u5c31\u9700\u8981\u6211\u4eec\u575a\u6301\u5b66\u4e60\u548c\u66f4\u65b0\u81ea\u5df1\u7684\u77e5\u8bc6\u3002\u4eca\u5929\u7c73\u4e91\u5c31\u6574\u7406\u5206\u4eab\u300a\u5982\u4f55\u4f7f\u7528 PHP \u51fd\u6570\u8bb0\u5f55\u5f02\u6b65\u65e5\u5fd7\uff1f\u300b\uff0c\u6587\u7ae0\u8bb2\u89e3\u7684\u77e5\u8bc6\u70b9\u4e3b\u8981\u5305\u62ec\uff0c\u5982\u679c\u4f60\u5bf9\u6587\u7ae0\u65b9\u9762\u7684\u77e5\u8bc6\u70b9\u611f\u5174\u8da3\uff0c\u5c31\u4e0d\u8981\u9519\u8fc7\u7c73\u4e91\uff0c\u5728\u8fd9\u53ef\u4ee5\u5bf9\u5927\u5bb6\u7684\u77e5\u8bc6\u79ef\u7d2f\u6709\u6240\u5e2e\u52a9\uff0c\u52a9\u529b\u5f00\u53d1\u80fd\u529b\u7684\u63d0\u5347\u3002<\/p>\n<p>PHP \u63d0\u4f9b\u4e86\u5f02\u6b65\u8bb0\u5f55\u51fd\u6570\uff0c\u5982 syslog() \u548c error_log()\uff0c\u7528\u4e8e\u5c06\u65e5\u5fd7\u6d88\u606f\u8bb0\u5f55\u5230\u5355\u72ec\u7684\u8fdb\u7a0b\u6216\u7ebf\u7a0b\uff0c\u63d0\u9ad8\u5e94\u7528\u7a0b\u5e8f\u6027\u80fd\u548c\u54cd\u5e94\u80fd\u529b\u3002\u5177\u4f53\u6b65\u9aa4\u5982\u4e0b\uff1a\u4f7f\u7528 syslog() \u6216 error_log() \u6253\u5f00\u65e5\u5fd7\u53e5\u67c4\u3002\u8bb0\u5f55\u65e5\u5fd7\u6d88\u606f\u3002\u5173\u95ed\u65e5\u5fd7\u53e5\u67c4\u3002<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.17golang.com\/uploads\/20241027\/1729990538671d8f8a7a733.jpg\" class=\"aligncenter\" title=\"\u5982\u4f55\u4f7f\u7528 PHP \u51fd\u6570\u8bb0\u5f55\u5f02\u6b65\u65e5\u5fd7\uff1f\u63d2\u56fe\" alt=\"\u5982\u4f55\u4f7f\u7528 PHP \u51fd\u6570\u8bb0\u5f55\u5f02\u6b65\u65e5\u5fd7\uff1f\u63d2\u56fe\" \/><\/p>\n<p><strong>\u5982\u4f55\u4f7f\u7528 PHP \u51fd\u6570\u8bb0\u5f55\u5f02\u6b65\u65e5\u5fd7<\/strong><\/p>\n<p><strong>\u524d\u8a00<\/strong><\/p>\n<p>\u5728\u7f16\u5199 PHP \u5e94\u7528\u7a0b\u5e8f\u65f6\uff0c\u8bb0\u5f55\u65e5\u5fd7\u81f3\u5173\u91cd\u8981\uff0c\u56e0\u4e3a\u5b83\u5141\u8bb8\u6211\u4eec\u8ddf\u8e2a\u5e94\u7528\u7a0b\u5e8f\u7684\u884c\u4e3a\u548c\u4e8b\u4ef6\u3002\u901a\u5e38\u60c5\u51b5\u4e0b\uff0c\u6211\u4eec\u5e0c\u671b\u8bb0\u5f55\u540c\u6b65\u4fe1\u606f\uff0c\u5373\u5f53\u5b83\u53d1\u751f\u65f6\u7acb\u5373\u5c06\u5176\u8bb0\u5f55\u4e0b\u6765\u3002\u7136\u800c\uff0c\u5728\u67d0\u4e9b\u60c5\u51b5\u4e0b\uff0c\u5f02\u6b65\u8bb0\u5f55\u5141\u8bb8\u6211\u4eec\u6539\u8fdb\u5e94\u7528\u7a0b\u5e8f\u7684\u6027\u80fd\u548c\u54cd\u5e94\u80fd\u529b\u3002<\/p>\n<p><strong>\u5f02\u6b65\u8bb0\u5f55<\/strong><\/p>\n<p>\u5f02\u6b65\u8bb0\u5f55\u662f\u5728\u4e00\u4e2a\u5355\u72ec\u7684\u8fdb\u7a0b\u6216\u7ebf\u7a0b\u4e2d\u8bb0\u5f55\u65e5\u5fd7\u6d88\u606f\u7684\u8fc7\u7a0b\u3002\u8fd9\u4f7f\u5f97\u4e3b\u5e94\u7528\u7a0b\u5e8f\u7ebf\u7a0b\u53ef\u4ee5\u7ee7\u7eed\u6267\u884c\uff0c\u800c\u4e0d\u4f1a\u88ab\u65e5\u5fd7\u8bb0\u5f55\u4efb\u52a1\u963b\u585e\u3002PHP \u63d0\u4f9b\u4e86\u51e0\u4e2a\u51fd\u6570\u6765\u5b9e\u73b0\u5f02\u6b65\u8bb0\u5f55\u3002<\/p>\n<p><strong>1. syslog()<\/strong><\/p>\n<pre>\/\/ \u6253\u5f00 syslog \u53e5\u67c4\nopenlog('my_application', LOG_PID | LOG_PERROR, LOG_USER);\n\n\/\/ \u8bb0\u5f55\u9519\u8bef\u7ea7\u522b\u6d88\u606f\nsyslog(LOG_ERR, 'Error message');\n\n\/\/ \u5173\u95ed syslog \u53e5\u67c4\ncloselog();<\/pre>\n<p><strong>2. error_log()<\/strong><\/p>\n<pre>\/\/ \u8bb0\u5f55\u9519\u8bef\u7ea7\u522b\u6d88\u606f\nerror_log('Error message', 0 | 1, 'my_application.log');<\/pre>\n<p><strong>\u5b9e\u6218\u6848\u4f8b<\/strong><\/p>\n<p>\u8003\u8651\u4e00\u4e2a\u5904\u7406\u5927\u91cf\u8bf7\u6c42\u7684 Web \u5e94\u7528\u7a0b\u5e8f\u3002\u540c\u6b65\u8bb0\u5f55\u6bcf\u4e2a\u8bf7\u6c42\u53ef\u80fd\u4f1a\u5bf9\u5e94\u7528\u7a0b\u5e8f\u6027\u80fd\u4ea7\u751f\u8d1f\u9762\u5f71\u54cd\u3002\u901a\u8fc7\u4f7f\u7528\u5f02\u6b65\u8bb0\u5f55\uff0c\u6211\u4eec\u53ef\u4ee5\u663e\u8457\u63d0\u9ad8\u5e94\u7528\u7a0b\u5e8f\u7684\u54cd\u5e94\u65f6\u95f4\u3002<\/p>\n<pre>\/\/ \u5728\u8bf7\u6c42\u5904\u7406\u51fd\u6570\u4e2d\n\/\/ \u4f7f\u7528 syslog \u5f02\u6b65\u8bb0\u5f55\u65e5\u5fd7\u6d88\u606f\nopenlog('my_application', LOG_PID | LOG_PERROR, LOG_USER);\nsyslog(LOG_INFO, 'Processing new request');\n\n\/\/ \u7ee7\u7eed\u5904\u7406\u8bf7\u6c42\u7684\u5176\u4ed6\u903b\u8f91\n\n\/\/ \u5728\u8bf7\u6c42\u5b8c\u6210\u540e\n\/\/ \u5173\u95ed syslog \u53e5\u67c4\ncloselog();<\/pre>\n<p><strong>\u7ed3\u8bba<\/strong><\/p>\n<p>\u901a\u8fc7\u4f7f\u7528 PHP \u7684\u5f02\u6b65\u8bb0\u5f55\u51fd\u6570\uff0c\u6211\u4eec\u53ef\u4ee5\u663e\u8457\u63d0\u9ad8\u5e94\u7528\u7a0b\u5e8f\u7684\u6027\u80fd\u548c\u54cd\u5e94\u80fd\u529b\u3002\u8fd9\u5bf9\u4e8e\u5904\u7406\u5927\u91cf\u8bf7\u6c42\u6216\u9700\u8981\u5728\u540e\u53f0\u6267\u884c\u4efb\u52a1\u7684\u5e94\u7528\u7a0b\u5e8f\u5c24\u4e3a\u91cd\u8981\u3002<\/p>\n<p>\u4eca\u5929\u5173\u4e8e\u300a\u5982\u4f55\u4f7f\u7528 PHP \u51fd\u6570\u8bb0\u5f55\u5f02\u6b65\u65e5\u5fd7\uff1f\u300b\u7684\u5185\u5bb9\u4ecb\u7ecd\u5c31\u5230\u6b64\u7ed3\u675f\uff0c\u5982\u679c\u6709\u4ec0\u4e48\u7591\u95ee\u6216\u8005\u5efa\u8bae\uff0c\u53ef\u4ee5\u5728\u7c73\u4e91\u516c\u4f17\u53f7\u4e0b\u591a\u591a\u56de\u590d\u4ea4\u6d41\uff1b\u6587\u4e2d\u82e5\u6709\u4e0d\u6b63\u4e4b\u5904\uff0c\u4e5f\u5e0c\u671b\u56de\u590d\u7559\u8a00\u4ee5\u544a\u77e5\uff01<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5982\u4f55\u4f7f\u7528 PHP \u51fd\u6570\u8bb0\u5f55\u5f02\u6b65\u65e5\u5fd7\uff1f \u7f16\u7a0b\u5e76\u4e0d\u662f\u4e00\u4e2a\u673a\u68b0\u6027\u7684\u5de5\u4f5c\uff0c\u800c\u662f\u9700\u8981\u6709\u601d\u8003\uff0c\u6709\u521b\u65b0\u7684\u5de5\u4f5c\uff0c\u8bed\u6cd5\u662f\u56fa\u5b9a\u7684\uff0c\u4f46\u89e3\u51b3\u95ee\u9898\u7684\u601d\u8def\u5219\u662f\u4f9d\u9760\u4eba\u7684\u601d\u7ef4\uff0c\u8fd9\u5c31\u9700\u8981\u6211\u4eec\u575a\u6301\u5b66\u4e60\u548c\u66f4\u65b0\u81ea\u5df1\u7684\u77e5\u8bc6\u3002\u4eca\u5929\u7c73\u4e91\u5c31\u6574\u7406\u5206\u4eab\u300a\u5982\u4f55\u4f7f\u7528 PHP \u51fd\u6570\u8bb0\u5f55\u5f02\u6b65\u65e5\u5fd7\uff1f\u300b\uff0c\u6587\u7ae0\u8bb2\u89e3\u7684\u77e5\u8bc6\u70b9\u4e3b\u8981\u5305\u62ec\uff0c\u5982\u679c\u4f60\u5bf9\u6587\u7ae0\u65b9\u9762\u7684\u77e5\u8bc6\u70b9\u611f\u5174\u8da3\uff0c\u5c31\u4e0d\u8981\u9519\u8fc7\u7c73\u4e91\uff0c\u5728\u8fd9\u53ef\u4ee5\u5bf9\u5927\u5bb6\u7684\u77e5\u8bc6\u79ef\u7d2f\u6709\u6240\u5e2e\u52a9\uff0c\u52a9\u529b\u5f00\u53d1\u80fd\u529b\u7684\u63d0\u5347\u3002 PHP \u63d0\u4f9b\u4e86\u5f02\u6b65\u8bb0\u5f55\u51fd\u6570\uff0c\u5982 syslog() \u548c error_log()\uff0c\u7528\u4e8e\u5c06\u65e5\u5fd7\u6d88\u606f\u8bb0\u5f55\u5230\u5355\u72ec\u7684\u8fdb\u7a0b\u6216\u7ebf\u7a0b\uff0c\u63d0\u9ad8\u5e94\u7528\u7a0b\u5e8f\u6027\u80fd\u548c\u54cd\u5e94\u80fd\u529b\u3002\u5177\u4f53\u6b65\u9aa4\u5982\u4e0b\uff1a\u4f7f\u7528 syslog() \u6216 error_log() \u6253\u5f00\u65e5\u5fd7\u53e5\u67c4\u3002\u8bb0\u5f55\u65e5\u5fd7\u6d88\u606f\u3002\u5173\u95ed\u65e5\u5fd7\u53e5\u67c4\u3002 \u5982\u4f55\u4f7f\u7528 PHP \u51fd\u6570\u8bb0\u5f55\u5f02\u6b65\u65e5\u5fd7 \u524d\u8a00 \u5728\u7f16\u5199 PHP \u5e94\u7528\u7a0b\u5e8f\u65f6\uff0c\u8bb0\u5f55\u65e5\u5fd7\u81f3\u5173\u91cd\u8981\uff0c\u56e0\u4e3a\u5b83\u5141\u8bb8\u6211\u4eec\u8ddf\u8e2a\u5e94\u7528\u7a0b\u5e8f\u7684\u884c\u4e3a\u548c\u4e8b\u4ef6\u3002\u901a\u5e38\u60c5\u51b5\u4e0b\uff0c\u6211\u4eec\u5e0c\u671b\u8bb0\u5f55\u540c\u6b65\u4fe1\u606f\uff0c\u5373\u5f53\u5b83\u53d1\u751f\u65f6\u7acb\u5373\u5c06\u5176\u8bb0\u5f55\u4e0b\u6765\u3002\u7136\u800c\uff0c\u5728\u67d0\u4e9b\u60c5\u51b5\u4e0b\uff0c\u5f02\u6b65\u8bb0\u5f55\u5141\u8bb8\u6211\u4eec\u6539\u8fdb\u5e94\u7528\u7a0b\u5e8f\u7684\u6027\u80fd\u548c\u54cd\u5e94\u80fd\u529b\u3002 \u5f02\u6b65\u8bb0\u5f55 \u5f02\u6b65\u8bb0\u5f55\u662f\u5728\u4e00\u4e2a\u5355\u72ec\u7684\u8fdb\u7a0b\u6216\u7ebf\u7a0b\u4e2d\u8bb0\u5f55\u65e5\u5fd7\u6d88\u606f\u7684\u8fc7\u7a0b\u3002\u8fd9\u4f7f\u5f97\u4e3b\u5e94\u7528\u7a0b\u5e8f\u7ebf\u7a0b\u53ef\u4ee5\u7ee7\u7eed\u6267\u884c\uff0c\u800c\u4e0d\u4f1a\u88ab\u65e5\u5fd7\u8bb0\u5f55\u4efb\u52a1\u963b\u585e\u3002PHP \u63d0\u4f9b\u4e86\u51e0\u4e2a\u51fd\u6570\u6765\u5b9e\u73b0\u5f02\u6b65\u8bb0\u5f55\u3002 1. syslog() \/\/ \u6253\u5f00 syslog \u53e5\u67c4 openlog(&#8216;my_application&#8217;, LOG_PID | LOG_PERROR, LOG_USER); \/\/ \u8bb0\u5f55\u9519\u8bef\u7ea7\u522b\u6d88\u606f syslog(LOG_ERR, &#8216;Error message&#8217;); \/\/ \u5173\u95ed syslog \u53e5\u67c4 closelog(); 2. error_log() \/\/ \u8bb0\u5f55\u9519\u8bef\u7ea7\u522b\u6d88\u606f error_log(&#8216;Error message&#8217;, 0 | 1, [&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-48121","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/48121","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=48121"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/48121\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=48121"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=48121"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=48121"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}