{"id":12106,"date":"2023-04-20T17:19:19","date_gmt":"2023-04-20T09:19:19","guid":{"rendered":"https:\/\/blog.hoyo.idv.tw\/?p=12106"},"modified":"2024-01-18T11:35:25","modified_gmt":"2024-01-18T03:35:25","slug":"php-%e4%b8%8d%e9%9c%80%e8%a6%81%e8%b3%87%e6%96%99%e5%ba%ab%e7%9a%84-linux-%e7%9b%a3%e6%8e%a7","status":"publish","type":"post","link":"https:\/\/blog.hoyo.idv.tw\/?p=12106","title":{"rendered":"PHP - \u4e0d\u9700\u8981\u8cc7\u6599\u5eab\u7684 Linux \u76e3\u63a7"},"content":{"rendered":"<p>--<\/p>\n<h2>\u6700\u7c21\u5316\u7684\u7db2\u9801\u76e3\u63a7\u65b9\u6848<\/h2>\n<p>\u51fa\u793e\u6703\u4e4b\u5f8c\u5f8c\u4f86\u56e0\u70ba\u90fd\u627e\u7a0b\u5f0f\u8a2d\u8a08\u5e2b\u7684\u5de5\u4f5c\uff0c\u56e0\u6b64\u5c31\u6bd4\u8f03\u5c11\u5728\u516c\u53f8\u8ca0\u8cac MIS \u76f8\u95dc\u5de5\u4f5c\u3002<\/p>\n<p>\u53ef\u662f\u4e00\u76f4\u90fd\u9084\u662f\u6709\u9047\u5230 Linux \u4f7f\u7528\u554f\u984c\uff0c\u4f8b\u5982\u9023\u7dda\u51fa\u554f\u984c\u662f\u56e0\u70ba\u8a18\u61b6\u9ad4\u9084\u662f\u983b\u5bec\u4e0d\u8db3\uff0c\u6216\u662f CPU \u8ca0\u8f09 100% \u7121\u6cd5\u8655\u7406\u3002\u53ef\u662f\u6c92\u6709\u4e00\u500b\u5f71\u97ff\u4e3b\u6a5f\u904b\u4f5c\u6700\u5c11\u7684\u76e3\u63a7\u5de5\u5177\uff0c\u76ee\u524d\u5e02\u9762\u4e0a\u7684\u5de5\u5177\u5927\u591a\u8981\u8cc7\u6599\u5eab\u5132\u5b58\u6578\u64da\uff0c\u9019\u6a23\u5149\u662f\u76e3\u63a7\u5c31\u8981\u8017\u8cbb\u6548\u80fd\uff0c\u6240\u4ee5 Hoyo \u53ea\u80fd\u81ea\u5df1\u8a2d\u8a08\u4e00\u5957\u4e0d\u4f7f\u7528\u8cc7\u6599\u5eab\u7684\u76e3\u63a7\u65b9\u6848\u3002<\/p>\n<p>\u6b64\u539f\u59cb\u78bc\u5206\u4eab\u5230 GitHub (<a href=\"https:\/\/github.com\/HoyoHuang\/linux-monitor-no-database\" target=\"_blank\" rel=\"noopener\" data-pjax=\"#repo-content-pjax-container\" data-turbo-frame=\"repo-content-turbo-frame\">linux-monitor-no-database<\/a>)<\/p>\n<p>--<\/p>\n<h2>\u601d\u8def<\/h2>\n<ul>\n<li>\u7531\u7db2\u9801\u524d\u7aef\u5b9a\u6642\u8a62\u554f\u4e3b\u6a5f\u7372\u53d6\u6578\u503c<\/li>\n<li>\u7372\u53d6\u6578\u503c\u5fc5\u9808\u76e1\u53ef\u80fd\u4f7f\u7528\u6700\u57fa\u672c\u7684\u7a0b\u5f0f\uff0c\u6e1b\u4f4e\u7372\u53d6\u6578\u503c\u6642\u7cfb\u7d71\u8ca0\u64d4<\/li>\n<li>\u5c07\u6578\u503c\u5132\u5b58\u5728 JavaScript \u9663\u5217<\/li>\n<li>\u4f7f\u7528\u9663\u5217\u6578\u503c\u7e6a\u88fd\u5716\u8868<\/li>\n<\/ul>\n<p>--<\/p>\n<h2>\u7279\u8272<\/h2>\n<ul>\n<li>\u4e0d\u9700\u8981\u8cc7\u6599\u5eab<\/li>\n<li>\u4e0d\u9700\u8981\u8a2d\u5b9a\u5b9a\u671f\u57f7\u884c<\/li>\n<li>\u4e0d\u9700\u8981\u57f7\u884c\u670d\u52d9<\/li>\n<li>\u53ef\u4ee5\u5f97\u5230 CPU \u8ca0\u8f09\u3001\u8a18\u61b6\u9ad4\u7a7a\u9593\u3001\u786c\u789f\u7a7a\u9593\u5373\u6642\u767e\u5206\u6bd4<\/li>\n<li>\u53ef\u4ee5\u5f97\u5230\u5373\u6642\u7db2\u8def\u6d41\u91cf\u4ee5\u53ca\u6700\u8fd1\u4e00\u5206\u9418\u6d41\u91cf\u5716\u8868<\/li>\n<li>\u624b\u52d5\u91cb\u653e\u8a18\u61b6\u9ad4\u5feb\u53d6 CACHE<\/li>\n<\/ul>\n<p>--<\/p>\n<h2>\u53d6\u5f97\u786c\u9ad4\u8cc7\u8a0a<\/h2>\n<ul>\n<li><a href=\"https:\/\/askubuntu.com\/questions\/988440\/how-do-i-get-the-model-name-of-my-processor\" target=\"_blank\" rel=\"noopener\">How do I get the model name of my processor?<\/a><\/li>\n<\/ul>\n<pre class=\"lang:default decode:true\">\/\/ cpu\r\n$command = \"grep -m1 'model name' \/proc\/cpuinfo\";\r\n$cpu_name = explode(':', shell_exec($command))[1];\r\n\r\n\/\/ \u8a18\u61b6\u9ad4\u5927\u5c0f\r\n$command = \" free -m | grep Mem: | awk '{print $2}' \";\r\n$ram_usage_total = shell_exec($command);\r\n\r\n\/\/ \u786c\u789f\u5927\u5c0f\r\n$command = \"fdisk -l | grep 'Disk \/dev\/sdb' | awk '{print $3 $4}'\";\r\n$hdd_size = shell_exec($command);<\/pre>\n<p>\u786c\u789f\u5927\u5c0f\u662f\u9700\u8981\u53d6\u5f97\u771f\u5be6\u5927\u5c0f\u4e0d\u662f\u5206\u5272\u5f8c\u5927\u5c0f\uff0c\u6240\u4ee5\u4f7f\u7528 fdisk<\/p>\n<p>\u9810\u8a2d fdisk -l \u5217\u51fa\u7684\u8cc7\u8a0a\u662f\uff1a<\/p>\n<pre class=\"lang:default decode:true \">Disk \/dev\/sda: 300 GiB, 322122547200 bytes, 629145600 sectors\r\nDisk model: VBOX HARDDISK   \r\nUnits: sectors of 1 * 512 = 512 bytes\r\nSector size (logical\/physical): 512 bytes \/ 512 bytes\r\nI\/O size (minimum\/optimal): 512 bytes \/ 512 bytes\r\nDisklabel type: dos\r\nDisk identifier: 0x5ecf7957\r\n\r\nDevice     Boot     Start       End   Sectors  Size Id Type\r\n\/dev\/sda1  *         2048 627144703 627142656  299G 83 Linux\r\n\/dev\/sda2       627146750 629143551   1996802  975M  5 Extended\r\n\/dev\/sda5       627146752 629143551   1996800  975M 82 Linux swap \/ Solaris<\/pre>\n<p>--<\/p>\n<h2>\u53d6\u5f97\u4f7f\u7528\u6578\u64da<\/h2>\n<p><strong>\u7db2\u7ad9\u9023\u7dda\u6578<\/strong><\/p>\n<pre class=\"lang:default decode:true \">\/\/ \u7db2\u7ad9\r\n$command = ' ss -tan | grep \":80 \" | grep -v grep | wc -l ';\r\n$netstat_80 = trim(shell_exec($command));\r\n\r\n$command = ' ss -tan | grep \":443 \" | grep -v grep | wc -l ';\r\n$netstat_443 = trim(shell_exec($command));\r\n\r\n$command = ' ss -tan | grep \":3306 \" | grep -v grep | wc -l ';\r\n$netstat_3306 = trim(shell_exec($command));\r\n\r\n\/\/ time wait\r\n$command = ' ss -tan | grep TIME-WAIT | grep -v grep | wc -l ';\r\n$netstat_time_wait = trim(shell_exec($command));<\/pre>\n<p><strong>\u7db2\u5361\u6d41\u91cf<\/strong><\/p>\n<ul>\n<li><a href=\"https:\/\/blog.51cto.com\/u_15127607\/3980215\" target=\"_blank\" rel=\"noopener\">\u76d1\u63a7\u7f51\u5361\u8bbe\u5907\u6d41\u91cf<\/a><\/li>\n<\/ul>\n<pre class=\"lang:default decode:true\">\/\/ RX\r\n$command = ' cat \/proc\/net\/dev | grep '. NetCode .' | tr : \" \" | awk \\'{print $2}\\' ';\r\n$net_rx = number_format(((int)shell_exec($command) \/ 1024\/1024), 2, '.', '');\r\n\r\n$command = ' cat \/proc\/net\/dev | grep '. NetCode .' | tr : \" \" | awk \\'{print $10}\\' ';\r\n$net_tx = number_format(((int)shell_exec($command) \/ 1024\/1024), 2, '.', '');<\/pre>\n<p><strong>\u786c\u789f\u7a7a\u9593<\/strong><\/p>\n<pre class=\"lang:default decode:true\">$a = exec('df \/');\r\n$a = preg_replace('\/\\s(?=\\s)\/', '', $a);\r\n$b = explode(' ', $a);\r\n$hdd_usage = $b[4];<\/pre>\n<p><strong>CPU \u4f7f\u7528\u8ca0\u8f09<\/strong><\/p>\n<pre class=\"lang:default decode:true \">$command = \"grep 'cpu ' \/proc\/stat | awk '{usage=($2+$4)*100\/($2+$4+$5)} END {print usage \\\"%\\\"}'\";\r\n$cpu_usage = number_format((float)shell_exec($command), 2, '.', '').'%';<\/pre>\n<p><strong>\u8a18\u61b6\u9ad4\u7a7a\u9593<\/strong><\/p>\n<p><img loading=\"lazy\" class=\"alignnone size-full wp-image-12119\" src=\"https:\/\/blog.hoyo.idv.tw\/wp-content\/uploads\/2023\/04\/2023-04-21-15-59-56.png\" alt=\"\" width=\"1155\" height=\"590\" srcset=\"https:\/\/blog.hoyo.idv.tw\/wp-content\/uploads\/2023\/04\/2023-04-21-15-59-56.png 1155w, https:\/\/blog.hoyo.idv.tw\/wp-content\/uploads\/2023\/04\/2023-04-21-15-59-56-300x153.png 300w, https:\/\/blog.hoyo.idv.tw\/wp-content\/uploads\/2023\/04\/2023-04-21-15-59-56-1024x523.png 1024w, https:\/\/blog.hoyo.idv.tw\/wp-content\/uploads\/2023\/04\/2023-04-21-15-59-56-768x392.png 768w\" sizes=\"(max-width: 1155px) 100vw, 1155px\" \/><\/p>\n<p>\u8a18\u61b6\u9ad4\u4e3b\u8981\u5340\u5206\u6709 used, shared,\u00a0 buff\/cache \u7b49\u6578\u503c<\/p>\n<pre class=\"lang:default decode:true\">$command = \" free -m | grep Mem: | awk '{print $2}' \";\r\n$ram_total = trim(shell_exec($command));\r\n$command = \" free -m | grep Mem: | awk '{print $3}' \";\r\n$ram_used = trim(shell_exec($command));\r\n$command = \" free -m | grep Mem: | awk '{print $5}' \";\r\n$ram_shared = trim(shell_exec($command));\r\n$command = \" free -m | grep Mem: | awk '{print $6}' \";\r\n$ram_buffer = trim(shell_exec($command));<\/pre>\n<p>\u56de\u50b3\u5f8c\u5728\u7db2\u9801\u4e0a\u9084\u539f\u6210<\/p>\n<p><img loading=\"lazy\" class=\"alignnone size-full wp-image-12122\" src=\"https:\/\/blog.hoyo.idv.tw\/wp-content\/uploads\/2023\/04\/2023-04-21-16-14-13.png\" alt=\"\" width=\"1127\" height=\"130\" srcset=\"https:\/\/blog.hoyo.idv.tw\/wp-content\/uploads\/2023\/04\/2023-04-21-16-14-13.png 1127w, https:\/\/blog.hoyo.idv.tw\/wp-content\/uploads\/2023\/04\/2023-04-21-16-14-13-300x35.png 300w, https:\/\/blog.hoyo.idv.tw\/wp-content\/uploads\/2023\/04\/2023-04-21-16-14-13-1024x118.png 1024w, https:\/\/blog.hoyo.idv.tw\/wp-content\/uploads\/2023\/04\/2023-04-21-16-14-13-768x89.png 768w\" sizes=\"(max-width: 1127px) 100vw, 1127px\" \/><\/p>\n<p>--<\/p>\n<h2>\u80cc\u666f\u57f7\u884c<\/h2>\n<ul>\n<li><a class=\"question-hyperlink\" href=\"https:\/\/stackoverflow.com\/questions\/30267329\/how-do-i-run-phps-built-in-web-server-in-the-background\" target=\"_blank\" rel=\"noopener\">How do I run PHP's built-in web server in the background?<\/a><\/li>\n<\/ul>\n<p>\u95dc\u9589\u7d42\u7aef\u9084\u53ef\u4ee5\u904b\u4f5c<\/p>\n<pre class=\"lang:default decode:true \">nohup php -S 0.0.0.0:8888 &amp;<\/pre>\n<p>--<\/p>\n<div class=\"pvc_clear\"><\/div>\n<p class=\"pvc_stats all \" data-element-id=\"12106\" style=\"\"><i class=\"pvc-stats-icon medium\" aria-hidden=\"true\"><svg aria-hidden=\"true\" focusable=\"false\" data-prefix=\"far\" data-icon=\"chart-bar\" role=\"img\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" viewBox=\"0 0 512 512\" class=\"svg-inline--fa fa-chart-bar fa-w-16 fa-2x\"><path fill=\"currentColor\" d=\"M396.8 352h22.4c6.4 0 12.8-6.4 12.8-12.8V108.8c0-6.4-6.4-12.8-12.8-12.8h-22.4c-6.4 0-12.8 6.4-12.8 12.8v230.4c0 6.4 6.4 12.8 12.8 12.8zm-192 0h22.4c6.4 0 12.8-6.4 12.8-12.8V140.8c0-6.4-6.4-12.8-12.8-12.8h-22.4c-6.4 0-12.8 6.4-12.8 12.8v198.4c0 6.4 6.4 12.8 12.8 12.8zm96 0h22.4c6.4 0 12.8-6.4 12.8-12.8V204.8c0-6.4-6.4-12.8-12.8-12.8h-22.4c-6.4 0-12.8 6.4-12.8 12.8v134.4c0 6.4 6.4 12.8 12.8 12.8zM496 400H48V80c0-8.84-7.16-16-16-16H16C7.16 64 0 71.16 0 80v336c0 17.67 14.33 32 32 32h464c8.84 0 16-7.16 16-16v-16c0-8.84-7.16-16-16-16zm-387.2-48h22.4c6.4 0 12.8-6.4 12.8-12.8v-70.4c0-6.4-6.4-12.8-12.8-12.8h-22.4c-6.4 0-12.8 6.4-12.8 12.8v70.4c0 6.4 6.4 12.8 12.8 12.8z\" class=\"\"><\/path><\/svg><\/i> &nbsp;1,154&nbsp;total views, &nbsp;1&nbsp;views today<\/p>\n<div class=\"pvc_clear\"><\/div>\n","protected":false},"excerpt":{"rendered":"<p>-- \u6700\u7c21\u5316\u7684\u7db2\u9801\u76e3\u63a7\u65b9\u6848 \u51fa...<\/p>\n<div class=\"pvc_clear\"><\/div>\n<p class=\"pvc_stats all \" data-element-id=\"12106\" style=\"\"><i class=\"pvc-stats-icon medium\" aria-hidden=\"true\"><svg aria-hidden=\"true\" focusable=\"false\" data-prefix=\"far\" data-icon=\"chart-bar\" role=\"img\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" viewBox=\"0 0 512 512\" class=\"svg-inline--fa fa-chart-bar fa-w-16 fa-2x\"><path fill=\"currentColor\" d=\"M396.8 352h22.4c6.4 0 12.8-6.4 12.8-12.8V108.8c0-6.4-6.4-12.8-12.8-12.8h-22.4c-6.4 0-12.8 6.4-12.8 12.8v230.4c0 6.4 6.4 12.8 12.8 12.8zm-192 0h22.4c6.4 0 12.8-6.4 12.8-12.8V140.8c0-6.4-6.4-12.8-12.8-12.8h-22.4c-6.4 0-12.8 6.4-12.8 12.8v198.4c0 6.4 6.4 12.8 12.8 12.8zm96 0h22.4c6.4 0 12.8-6.4 12.8-12.8V204.8c0-6.4-6.4-12.8-12.8-12.8h-22.4c-6.4 0-12.8 6.4-12.8 12.8v134.4c0 6.4 6.4 12.8 12.8 12.8zM496 400H48V80c0-8.84-7.16-16-16-16H16C7.16 64 0 71.16 0 80v336c0 17.67 14.33 32 32 32h464c8.84 0 16-7.16 16-16v-16c0-8.84-7.16-16-16-16zm-387.2-48h22.4c6.4 0 12.8-6.4 12.8-12.8v-70.4c0-6.4-6.4-12.8-12.8-12.8h-22.4c-6.4 0-12.8 6.4-12.8 12.8v70.4c0 6.4 6.4 12.8 12.8 12.8z\" class=\"\"><\/path><\/svg><\/i> &nbsp;1,154&nbsp;total views, &nbsp;1&nbsp;views today<\/p>\n<div class=\"pvc_clear\"><\/div>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[31],"tags":[],"_links":{"self":[{"href":"https:\/\/blog.hoyo.idv.tw\/index.php?rest_route=\/wp\/v2\/posts\/12106"}],"collection":[{"href":"https:\/\/blog.hoyo.idv.tw\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.hoyo.idv.tw\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.hoyo.idv.tw\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.hoyo.idv.tw\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=12106"}],"version-history":[{"count":12,"href":"https:\/\/blog.hoyo.idv.tw\/index.php?rest_route=\/wp\/v2\/posts\/12106\/revisions"}],"predecessor-version":[{"id":13044,"href":"https:\/\/blog.hoyo.idv.tw\/index.php?rest_route=\/wp\/v2\/posts\/12106\/revisions\/13044"}],"wp:attachment":[{"href":"https:\/\/blog.hoyo.idv.tw\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=12106"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.hoyo.idv.tw\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=12106"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.hoyo.idv.tw\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=12106"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}