I have a server with the following specifications:
- 1 vCPU
- 1 GB RAM
- 25 GB SSD
Configured with Linux Ubuntu 18.04
, apache 2
and php 7.2
.
Let's assume that for each visitor entering my page, I run a command in background mode, where it counts from 0 to 100,000 - 1 million:
index.php
exec("php ./countToOneMilion.php > /dev/null &");//This code runs a php file in background mode (if the user closes a browser window, a count still continues)
countToOneMilion.php
$number = mt_rand(100000, 1000000);//Generate a random number
for ($i = 0; $i <= $number; $i++) {
echo $i;
}
According to phpinfo()
, the memory_limity
parameter of my server, is set to 127M
(which is the default value when installing php and apache).
Now, let's assume that 20 visitors entered in my page. In that case, how will PHP execute the processes in background mode (since counting from 0 to 1 million is often a time-consuming task)?
Will it run 20 times simultaneously (dividing the 127M by 20, thats the number of processes) or will some processes stay on a waiting list until the other processes are over? Or is PHP only able to execute one process at a time (causing the last task from the last user to wait a considerable amount of time to get the count from 0 to 1 million?)