I have AMPPS installed.
My Apache server cannot handle multiple php requests at once (for example if I call localhost/script.php
multiple times, they are processed in a consecutive order). script.php
consists only of <?php sleep(10); ?>
.
I read that MaxClients directive is responsible for concurrent access configuration, but it is missing in my httpd.conf
at all.
Disabling Xdebug and writing session_write_close();
to the beginning of the script didn't work.
When I added session_start();
to the beginning of the file and my code looked like:
<?php
session_start();
session_write_close();
sleep(10);
phpinfo();
echo "Done";
When making 5 requests to localhost/script.php
, last 4 waited for the first one to end and then ended concurrently.
Please, help me resolve the issue. If any information that is needed to help me resolve this problem is missing, please notify and I will add it.
With this number of instantiated workers, Apache can handle almost 160 requests per second without increasing the number of workers. Assuming the number of requests and the CPU time are linearly dependent, this leads to CPU consumption of about 30%.
The Apache server works by handling URL requests to the server through specific communication protocols in a multithreading fashion, and extending itself to work with programming and database languages.
Requests are handled in parallel by the web server (which runs the PHP script). Updating data in the database is pretty fast, so any update will appear instantaneous, even if you need to update multiple tables.
PHP does not handle requests. The web server does. For Apache HTTP Server , the most popular is "mod_php". This module is actually PHP itself, but compiled as a module for the web server, and so it gets loaded right inside it.
Apache can surely handle multiple requests at the same time, there is something surely going wrong within your apache configuration.
It depends on which version of Apache you are using and how it is configured, but a common default configuration uses multiple workers with multiple threads to handle simultaneous requests. See http://httpd.apache.org/docs/2.2/mod/worker.html for a rundown of how this works.
The reason why you are facing it is: There is some lock somewhere - which can happen, for instance, if the two requests come from the same client, and you are using file-based sessions in PHP : while a script is being executed, the session is "locked", which means the server/client will have to wait until the first request is finished (and the file unlocked) to be able to use the file to open the session for the second user.
The requests come from the same client AND the same browser; most browsers will queue the requests in this case, even when there is nothing server-side producing this behaviour.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With