title: PHP site freeze/crash but static contents fine
body: <p>I have a PHP site where users upload a lot of photos. The photos are cropped in the front end and sent as base64 in a POST form. The max size is around 80kB.</p>
  <p><strong>JavaScript:</strong></p>
  <pre><code>document.getElementById('image').src = dataurl;   To display croped image on the browser
  document.getElementById('inddeninput').value = dataurl; To set hidden input value
  </code></pre>
  <p><strong>Then ajax call to submit to PHP</strong></p>
  <pre><code>axios({
    method: 'post',
    url: `url/to/php/file`,
    data: formData,
    headers: {'Content-Type': 'multipart/form-data' }
    })
  </code></pre>
  <p><strong>The PHP script:</strong></p>
  <pre><code>$img = $_POST['img'];
  
  $dataImg = base64_decode($img);
  
  file_put_contents($fileLocation, $dataImg);
  </code></pre>
  <p>Then insert/update the MySQL(Mariadb) table with the location of the image.</p>
  <pre><code>$response = location of the image;
  echo json_encode($response);
  </code></pre>
  <p><strong>Hosting:</strong></p>
  <p>It's hosted on a VPS with 4CPU and 8GB. PHP 7.4 and Apache 2.4 running mpm_event.</p>
  <p><strong>The Issue</strong></p>
  <p>Everything's fine when there are fewer users.</p>
  <p>When there are a lot of concurrent users (approximately 400), the entire site is very slow and takes 30 seconds or more to respond. However, there are no Apache error logs, no site error logs, nothing, and if I restart Apache its fine for a few minutes.</p>
  <p>If I try to load a static file like an image from the site(mydomain.com/public/images/img.1.jpg) it is very fast and takes less than a second.</p>
  <p>What things can I try to solve this?</p>
  <h2>Edit</h2>
  <p>After a lot of digging around I found the issue in the /var/log/php7.4-fpm.log</p>
  <pre><code>[pool www] server reached pm.max_children setting (96), consider 
  raising it
  </code></pre>
  <p>It was the php_fpm module child connections. I had the following settings before:</p>
  <pre><code>pm.max_children = 96
  pm.start_servers = 48
  pm.min_spare_servers = 32
  pm.max_spare_servers = 64
  </code></pre>
  <p>A lot of my users are on slow connections, and I guess subsequent requests went on queue. I have increased the values and the situation has improved.</p>