title: How to make async ajax request really async?
body: <p>I added new feature on my site. Administrator uploading archive with some pictures (rent recepits) and these picture are sending to users. There are 50-100 users on my site atm. Max users is 700-1000. </p>
  
  <p>I am sending email with php <code>mail()</code> function. It takes time. It takes ~3.5 seconds to send 1 message via <code>mail()</code>. I need to send at least 100 messages. </p>
  
  <p>I had next code structure: </p>
  
  <p><code>Main script</code>: </p>
  
  <ol>
  <li>drawing form with input type=file</li>
  <li>uploading archive with this
  form </li>
  <li>check name of archive, content of archive. All files must be
  of a certain format</li>
  <li>Making an ajax request to script
  <code>send_rent_receipts.php</code>. Month and year are sending as parameters</li>
  </ol>
  
  <p><code>send_rent_receipts.php</code> (getting month and year):</p>
  
  <ol>
  <li>unpack files to directory <code>.../$year/$month</code></li>
  <li>foreach file in directory <code>.../$year/$month</code> do:<br>
  
  <ul>
  <li>get name of file (name is like 774.pdf, 772.pff — name of file    connect this file to user</li>
  <li>get e-mail of user</li>
  <li>send e-mail with attachement (current file)</li>
  </ul></li>
  </ol>
  
  <p>This method was working for ~35 seconds with 10 files. ~3.5 seconds with 1 file. </p>
  
  <p>My hosting provider set <code>max_execution_time 30</code> in <code>php.ini</code> so this script fails (because it is working much more then 30 seconds.</p>
  
  <p>I tried another method:</p>
  
  <p><code>main script</code>:
  <br></p>
  
  <ol>
  <li>drawing form with input type=file</li>
  <li>uploading archive with this form</li>
  <li>check name of archive, content of archive. All files must be of a certain format</li>
  <li>unpack archive to directory <code>.../$year/$month</code></li>
  <li>foreach file in directory <code>.../$year/$month</code> do 
  
  <ul>
  <li>get file name</li>
  <li>make ajax request to script <code>send_rent_receipts.php</code> (filename, month, year are sending)</li>
  </ul></li>
  </ol>
  
  <p><code>send_php_script.php</code>:
  <br></p>
  
  <ol>
  <li>get user data/e-mail </li>
  <li>send file <code>.../$year/$month/$filename</code> to this
  mail</li>
  </ol>
  
  <p>I thought this method is what I need. Server will make not 1 ajax request, but XX ajax requests (depending on amount of files). Each request will work for 3.5 seconds. Ajax requests are async (I thought. And they must be) so all process (XX ajax requests) will work for 3.5 seconds.</p>
  
  <p>But... What I see? There are 3 images with tests with different amount of files (1, 3, 10 files):</p>
  
  <p>Sending 1 e-mail: <br>
  <img src="https://i.stack.imgur.com/szaU9.png" alt="1 e-mail"> 
  <br></p>
  
  <p>Sending 3 e-mails:<br>
  <img src="https://i.stack.imgur.com/IMINn.png" alt="3 e-mails"><br></p>
  
  <p>Sending 10 e-mails:<br>
  <img src="https://i.gyazo.com/c9bb844c56a0cad732b9ee598d8d392a.png" alt="10 e-mails"><br></p>
  
  <p>Why ajax requests (<code>async: true</code> as default) are working as not async requests. This images shows, that 10 ajax requests to script which send 1 e-mail takes same time as 1 requests to script which send 10 e-mails.</p>
  
  <p>Why it is so? I thought they must be async and all subscribe will take 3.5 seconds.</p>
  
  <p>How to reduce script execution time? what a way to make it run faster</p>
  
  <p>P.S.: files are not equal, so I can't send 1 e-mail to 10 recepients. </p>