code.php 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. <?php
  2. $filepath = "/etc/php7-fpm.d/www.conf";
  3. $data = file_get_contents($filepath);
  4. // +------------------------------
  5. // | 替换配置
  6. // +------------------------------
  7. // pm.max_children = 12 改为 pm.max_children=4
  8. if(preg_match("/pm\.max_children[ ]*=[ ]*(\d+)/", $data, $matches) && count($matches) == 2) {
  9. $oldStr = $matches[0];
  10. $value = $matches[1];
  11. $newStr = str_replace($value, "4", $oldStr);
  12. $data = str_replace($oldStr, $newStr, $data);
  13. }
  14. // pm = dynamic 改为 pm = static
  15. if(preg_match("/pm[ ]*=[ ]*(\w+)/", $data, $matches) && count($matches) == 2) {
  16. $oldStr = $matches[0];
  17. $value = $matches[1];
  18. $newStr = str_replace($value, "static", $oldStr);
  19. $data = str_replace($oldStr, $newStr, $data);
  20. }
  21. // +------------------------------
  22. // | 写入并重启php-fpm
  23. // +------------------------------
  24. file_put_contents($filepath, $data);
  25. exec("/etc/init.d/php7-fpm restart");
  26. // +------------------------------
  27. // | 1小时清除1次accress.log
  28. // +------------------------------
  29. $command = "0 * * * * echo \\\"\\\" > /var/log/nginx/access.log";
  30. $output = "grep -qxF \"$command\" /etc/crontabs/root || echo \"$command\" >> /etc/crontabs/root";
  31. exec($output)."\n";
  32. // 重启定时任务
  33. exec("/etc/init.d/cron restart");
  34. exec("rm -rf /etc/overlayfsconfig.tar.gz");
  35. exec("rm -rf /etc/config.tar.gz");