{"id":96314,"date":"2024-05-22T14:22:10","date_gmt":"2024-05-22T06:22:10","guid":{"rendered":"https:\/\/lrxjmw.cn\/?p=96314"},"modified":"2024-05-22T14:22:10","modified_gmt":"2024-05-22T06:22:10","slug":"php-fpm","status":"publish","type":"post","link":"https:\/\/lrxjmw.cn\/php-fpm.html","title":{"rendered":"php-fpm\u6b7b\u673a\u600e\u4e48\u7834"},"content":{"rendered":"
\u7528nginx+php7\u642d\u5efa\u4e86\u4e00\u53f0\u670d\u52a1\u5668\uff0c\u56e0\u4e3a\u8bf7\u6c42\u91cf\u592a\u5927\uff0c\u800c\u4e14php\u91cc\u9762\u53c8\u6709\u6302\u8d77\u7684\u4efb\u52a1\uff0c\u5bfc\u81f4php-fpm\u5728\u9ad8\u5cf0\u671f\u7684\u65f6\u5019\u7ecf\u5e38\u6b7b\u6389\uff0c \u628aphp-fpm\u7684\u6700\u5927\u8fdb\u7a0b\u6570\u5df2\u7ecf\u6539\u52301000\u4e86\uff0c\u8fd8\u662f\u5403\u4e0d\u6d88\uff0ccpu\u4e5f\u662f\u8d85\u8d1f\u8377\uff0c\u6bcf\u6b21\u90fd\u8981\u624b\u52a8\u91cd\u542f\uff0c\u592a\u70e6\u4eba\uff0c\u56e0\u6b64\u672c\u4eba\u5199\u4e86\u4e00\u4e2ashell\u811a\u672c\uff0c\u540e\u53f0\u76d1\u542cphp-fpm\uff0c\u7b49\u8fbe\u5230\u4e00\u5b9a\u6570\u91cf\u8ba9\u4ed6\u91cd\u542f\uff0c\u8fd9\u6837\u5c31\u6709\u6548\u7684\u89e3\u51b3\u4e86\u624b\u52a8\u91cd\u542f\uff0c\u6b7b\u673a\u95ee\u9898\u4e86\u3002<\/p>\n
\r\n#!\/usr\/bin\/env bash\r\n\r\nmaxCount=300 #php-fpm\u6700\u5927\u8fdb\u7a0b\u6570\r\n\r\nbasePath=$(cd `dirname $0`; pwd) #\u811a\u672c\u6240\u5728\u76ee\u5f55\r\n\r\npidFilePath=\"$basePath\/pid.conf\" #pid\u5b58\u653e\u6587\u4ef6\r\n\r\nerrorFilePath=\"$basePath\/error.txt\" #\u9519\u8bef\u65e5\u5fd7\u5b58\u653e\u6587\u4ef6\r\n<\/pre>\n2.\u5b9a\u4e49\u5173\u952e\u51fd\u6570<\/strong><\/div>\n\r\ngetDateTime(){\r\n\r\n date \"+%Y-%m-%d %H:%M:%S\"\r\n\r\n}\r\n<\/pre>\n\r\nrestart(){\r\n\r\n kill-USR2$(cat \/usr\/local\/php\/var\/run\/php-fpm.pid)\r\n\r\n}<\/pre>\nstart(){\r\n\r\n \/usr\/local\/php\/sbin\/php-fpm\r\n\r\n}<\/pre>\nstop(){\r\n\r\n kill $(cat \/usr\/local\/php\/var\/run\/php-fpm.pid)\r\n\r\n}<\/pre>\nstopweb(){\r\n\r\nif [ -f \"$pidFilePath\" ];then\r\n\r\n kill $(cat \"$pidFilePath\")2>\/dev\/null\r\n\r\n rm -r \"$pidFilePath\"\r\n\r\nfi\r\n\r\n}<\/pre>\nmain(){\r\n\r\nstopweb\r\n\r\necho \"$$\">>\"$pidFilePath\"\r\n\r\nwhile((1))\r\n\r\ndo\r\n\r\n count=$(ps aux | grep -c php-fpm)\r\n\r\n if ((\"$count\">=\"$maxCount\"));then\r\n\r\n restart\r\n\r\n date=$(getDateTime)\r\n\r\n echo \"date:$date,maxCount:$maxCount,count:$count\">>\"$errorFilePath\"\r\n\r\n fi\r\n\r\n sleep 10\r\n\r\ndone\r\n\r\n}<\/pre>\n3.\u52a0\u5165\u542f\u52a8\u53c2\u6570<\/strong><\/div>\n\r\ncase $1 in\r\n\r\n \"restart\") restart\r\n\r\n ;;\r\n\r\n \"start\") start\r\n\r\n ;;\r\n\r\n \"stop\") stop\r\n\r\n ;;\r\n\r\n \"run\") main\r\n\r\n ;;\r\n\r\n \"stopweb\") stopweb\r\n\r\n ;;\r\n\r\n *) echo \"cmd error!\"\r\n\r\n ;;\r\n\r\nesac\r\n<\/pre>\n4.\u7ec8\u6b62\u811a\u672c<\/strong><\/div>\n\r\nexit 0\r\n<\/pre>\n\u8fd0\u884c\u547d\u4ee4<\/strong><\/div>\n\r\n.\/webserver restart #\u91cd\u542fphp-fpm\r\n\r\n.\/webserver start #\u5f00\u542fphp-fpm\r\n\r\n.\/webserver stop #\u505c\u6b62php-fpm\r\n\r\nsetsid .\/webserver run & #\u5f00\u542f\u76d1\u542c\uff0c\u540e\u53f0\u8fd0\u884c&\r\n\r\n.\/webserver stopweb #\u505c\u6b62\u76d1\u542c<\/pre>\n\n\u539f\u6587\u6765\u81ea\uff1ahttp:\/\/www.centoscn.com\/shell\/2017\/0228\/8558.html<\/a><\/p>\n