i use xampp with apache php server
i send request A to the server and keep it busy. then before the server finish the execution i send another immediate request B. but the server won’t response to B until it finish the previous execution requested by A, make B on client side keep waiting. so i expect that the server doesn’t automatically multithread the request came from a client. my question is
-
is that
the client is meant to receive the response of previous request before the
next request can be sent? i try to set the ajax to synchronous and it still doesnt workOR
we can use php multithreading feature to deal with it
-
if there is a way, can we share the resource among the requests? let say req A put some value into $_SESSION and req B want to read it
Make sure you don’t confuse the idea of a particular PHP process being multi-threaded with the web server itself being multi-threaded. PHP doesn’t really support multi-threading from within PHP code. However, the server is multi-threaded and can be processing multiple PHP requests at the same time.
When you send off request “A”, the webserver is going to start processing that request in a new thread. When request “B” comes in, the server will start another new thread to handle it. If “B” starts before “A” is finished, then they’ll both be running at the same time, but there’s really no way to synchronize them.
If “A” needs to be finished before it makes sense to do “B”, you’re really going to need to have the client wait until it hears that “A” is done, then send off request “B”. The usual way to do that is to have the “success” code for the “A” request send off request “B”.
If you’re wanting “B” to read something out of the session that was set by “A” you definitely need do make sure “A” is finished at the client before doing “B”.