{"id":6738,"date":"2014-10-28T21:50:51","date_gmt":"2014-10-28T13:50:51","guid":{"rendered":"http:\/\/jpuyy.com\/?p=6738"},"modified":"2016-09-30T10:56:24","modified_gmt":"2016-09-30T02:56:24","slug":"strace-analysis-nginx-php-execute","status":"publish","type":"post","link":"https:\/\/jpuyy.com\/?p=6738","title":{"rendered":"strace\u5206\u6790apache php\u8fdb\u7a0b\u6267\u884c"},"content":{"rendered":"<p>\u770b\u4e86\u5916\u56fd\u4eba\u5236\u4f5c\u7684\u6392\u67e5apache\u7f51\u9875\u5f88\u6162\u7684\u89c6\u9891\u987f\u65f6\u5b66\u4e60\u5230\u4e86\u5f88\u591a\uff0c\u5e94\u8be5\u591a\u770b\u56fd\u5916\u7684\u89c6\u9891\uff0c\u94fe\u63a5http:\/\/www.youtube.com\/watch?v=eF-p&#8211;AH37E<\/p>\n<p>\u8fd9\u4e2a\u4f8b\u5b50\u4ecb\u7ecd\u4e86\u6709\u4e00\u4e2a\u7f51\u9875\u6253\u5f00\u6bd4\u5176\u4ed6\u7f51\u9875\u8981\u6162\uff0ctelnet\u53bb\u6d4b\u8bd5GET\u8bf7\u6c42\uff0c\u6211\u8fd9\u91cc\u7528nginx\u505a\u6d4b\u8bd5<\/p>\n<pre>\u279c   telnet jpuyy.com 80\r\nTrying 114.215.158.48...\r\nConnected to jpuyy.com.\r\nEscape character is '^]'.\r\nGET \/ HTTP\/1.1\r\nHost: jpuyy.com\r\n<\/pre>\n<p>\u8fd9\u65f6\u56de\u8f66\u4e00\u6b21\uff0c\u8fd9\u6837\u4e0e\u670d\u52a1\u5668keep-alive\u3002<br \/>\n\u53e6\u6253\u5f00\u4e00\u4e2a\u7a97\u53e3\uff0c\uff0c\u7528pidof nginx\u627e\u5230\u6b64\u8fdb\u7a0b\u7684pid\uff0c\u7528lsof -p\u67e5\u770b\u6b64pid\u90fd\u6253\u5f00\u4e86\u54ea\u4e9b\u6587\u4ef6\uff0c\u540c\u65f6\u4e5f\u80fd\u770b\u5230tcp ESTABLISHED\u53ca\u6253\u5f00\u7684\u7aef\u53e3\uff0c\u8fd9\u91cc\u5c31\u80fd\u786e\u5b9a\u662f\u54ea\u4e2anginx\u8fdb\u7a0b\u6765\u5904\u7406\u7528\u6237\u8bf7\u6c42\u3002<\/p>\n<pre>for i in `pidof nginx`; do lsof -n -p $i|grep ESTABLISHED; done\r\nnginx   28170 nginx   14u  IPv4            8920667      0t0     TCP 114.215.158.48:http-&gt;91.200.12.90:61110 (ESTABLISHED)\r\n<\/pre>\n<p>\u5728\u670d\u52a1\u5668\u4e0a\u7ed3\u5408top\uff0c\u6309\u4e0bshift+u\uff0c\u8f93\u5165nginx\u8fc7\u6ee4\u53ea\u6709nginx\u7528\u6237\u7684\u8fdb\u7a0b\u3002<\/p>\n<p>\u627e\u5230pid\u4e4b\u540e\uff0c\u7528strace -p pid\u5206\u6790\u8bf7\u6c42\u5230\u5e95\u90fd\u505a\u4e86\u4ec0\u4e48\u3002\u8fd9\u91cc\u662f\u8981\u627e\u7f51\u9875\u53d8\u6162\u7684\u56e0\u7d20\uff0c\u52a0\u4e0a-r\u53c2\u6570\u663e\u793a\u65f6\u95f4\u8fc7\u7a0b\uff0c\u7528\u4e8e\u67e5\u770b\u662f\u54ea\u4e00\u6b65\u53d8\u6162\u7684\uff0c-o \u8ddffilename\u5c06\u8f93\u51fa\u91cd\u5b9a\u5411\u5230\u6587\u4ef6\u4e2d\uff0c\u4ee5\u4e0b\u662f\u5b8c\u6574\u547d\u4ee4\u3002<\/p>\n<pre>strace -o file -r -p 28170<\/pre>\n<p>\u63a5\u4e0b\u6765\u6253\u5f00\u53ef\u4ee5\u67e5\u770bworker\u662f\u5982\u4f55\u5de5\u4f5c\u7684\uff0c\u6253\u5f00\u6587\u4ef6\uff0c\u8fd0\u884c\u547d\u4ee4\uff0c\u8c03\u7528\u7cfb\u7edf\u6587\u4ef6\uff0c\u8c03\u7528php\u3002\u56e0\u4e3a\u52a0\u4e86-r\u53c2\u6570\uff0c\u53ef\u4ee5\u770b\u5230\u6bcf\u4e00\u6b65\u8fd0\u884c\u7684\u65f6\u95f4\u3002\u53ef\u4ee5\u76f4\u63a5\u7528awk\u6216cut\u7ed3\u5408sort\u627e\u51fa\u8fd0\u884c\u65f6\u95f4\u6700\u957f\u7684\u4e00\u6b65\uff0c\u67e5\u770b\u5b83\u662f\u56e0\u4e3adns\u539f\u56e0\uff0c\u8fd8\u662fphp\u8fd0\u884c\u51fd\u6570\u5bfc\u81f4\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u770b\u4e86\u5916\u56fd\u4eba\u5236\u4f5c\u7684\u6392\u67e5apache\u7f51\u9875\u5f88\u6162\u7684\u89c6\u9891\u987f\u65f6\u5b66\u4e60\u5230\u4e86\u5f88\u591a\uff0c\u5e94\u8be5\u591a\u770b\u56fd\u5916\u7684\u89c6\u9891\uff0c\u94fe\u63a5http:\/\/www.youtube.com\/watch?v=eF-p&#8211;AH37E \u8fd9\u4e2a\u4f8b\u5b50\u4ecb\u7ecd\u4e86\u6709\u4e00\u4e2a\u7f51\u9875\u6253\u5f00\u6bd4\u5176\u4ed6\u7f51\u9875\u8981\u6162\uff0ctelnet\u53bb\u6d4b\u8bd5GET\u8bf7\u6c42\uff0c\u6211\u8fd9\u91cc\u7528nginx\u505a\u6d4b\u8bd5 \u279c telnet jpuyy.com 80 Trying 114.215.158.48&#8230; Connected to jpuyy.com. Escape character is &#8216;^]&#8217;. GET \/ HTTP\/1.1 Host: jpuyy.com \u8fd9\u65f6\u56de\u8f66\u4e00\u6b21\uff0c\u8fd9\u6837\u4e0e\u670d\u52a1\u5668keep-alive\u3002 \u53e6\u6253\u5f00\u4e00\u4e2a\u7a97\u53e3\uff0c\uff0c\u7528pidof nginx\u627e\u5230\u6b64\u8fdb\u7a0b\u7684pid\uff0c\u7528lsof -p\u67e5\u770b\u6b64pid\u90fd\u6253\u5f00\u4e86\u54ea\u4e9b\u6587\u4ef6\uff0c\u540c\u65f6\u4e5f\u80fd\u770b\u5230tcp ESTABLISHED\u53ca\u6253\u5f00\u7684\u7aef\u53e3\uff0c\u8fd9\u91cc\u5c31\u80fd\u786e\u5b9a\u662f\u54ea\u4e2anginx\u8fdb\u7a0b\u6765\u5904\u7406\u7528\u6237\u8bf7\u6c42\u3002 for i in `pidof nginx`; do lsof -n -p $i|grep ESTABLISHED; done nginx 28170 nginx 14u IPv4 8920667 0t0 TCP 114.215.158.48:http-&gt;91.200.12.90:61110 (ESTABLISHED) \u5728\u670d\u52a1\u5668\u4e0a\u7ed3\u5408top\uff0c\u6309\u4e0bshift+u\uff0c\u8f93\u5165nginx\u8fc7\u6ee4\u53ea\u6709nginx\u7528\u6237\u7684\u8fdb\u7a0b\u3002 \u627e\u5230pid\u4e4b\u540e\uff0c\u7528strace -p pid\u5206\u6790\u8bf7\u6c42\u5230\u5e95\u90fd\u505a\u4e86\u4ec0\u4e48\u3002\u8fd9\u91cc\u662f\u8981\u627e\u7f51\u9875\u53d8\u6162\u7684\u56e0\u7d20\uff0c\u52a0\u4e0a-r\u53c2\u6570\u663e\u793a\u65f6\u95f4\u8fc7\u7a0b\uff0c\u7528\u4e8e\u67e5\u770b\u662f\u54ea\u4e00\u6b65\u53d8\u6162\u7684\uff0c-o \u8ddffilename\u5c06\u8f93\u51fa\u91cd\u5b9a\u5411\u5230\u6587\u4ef6\u4e2d\uff0c\u4ee5\u4e0b\u662f\u5b8c\u6574\u547d\u4ee4\u3002 strace -o file [&hellip;]<\/p>\n","protected":false},"author":3,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[64],"tags":[],"class_list":["post-6738","post","type-post","status-publish","format-standard","hentry","category-web"],"_links":{"self":[{"href":"https:\/\/jpuyy.com\/index.php?rest_route=\/wp\/v2\/posts\/6738","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/jpuyy.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/jpuyy.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/jpuyy.com\/index.php?rest_route=\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/jpuyy.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=6738"}],"version-history":[{"count":7,"href":"https:\/\/jpuyy.com\/index.php?rest_route=\/wp\/v2\/posts\/6738\/revisions"}],"predecessor-version":[{"id":6786,"href":"https:\/\/jpuyy.com\/index.php?rest_route=\/wp\/v2\/posts\/6738\/revisions\/6786"}],"wp:attachment":[{"href":"https:\/\/jpuyy.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=6738"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/jpuyy.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=6738"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/jpuyy.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=6738"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}