使用php soap客户端的奇怪的超时行为

I'm trying to make a proxy-like page that forwards an AJAX request to a SOAP server. The browser sends 2 requests to the same page (i.e. server.php with different query string) every 10 seconds. The server makes a soap call to the soap server depending on the query string. All is working fine.

Then I put a sleep (40 secs) in the soap server to simulate a slow response and I also put a timeout on the caller to abort the call after some seconds.

server.php: Pseudo code:

$timeout = 10;
ini_set("default_socket_timeout", $timeout);

$id = $_GET['id'];

$wsdl= 'http://soapserver/wsdl'
$client = new SoapClient($wsdl,array('connection_timeout'=> $timeout));
print($client->getQuote($id));

If the browser sends an ajax request to http://myserver/server.php?id=IBM the request stops after the timeout I set. If I try to make a second call before the first stops, the second one doesn't not respect timeout.

i.e.

Request:

GET http://myserver/server.php?id=IBM 
and after 1 second 
GET http://myserver/server.php?id=AAP

Response:

after 10 seconds:
No data
after 20 seconds:
No data

I also tried to not use PHP SOAP and use curl instead but I got the same results.

I also tried to open 3 tabs on my browser and call:

http://myserver/server.php?id=IBM
http://myserver/server.php?id=AAP
http://myserver/server.php?id=MSX

The first one stops after 10 seconds, the second after 20 seconds and the third after 30 seconds.

Is this a normal behaviour or I miss something ? Thanks in advance

You are probably starting sessions, and session_start() blocks a second call to it until the other request has 'freed' the session (in other words: has finished and will not write any data to the session anymore). For time consuming requests, don't start a session if you don't need one, and if you DO need one, get all the data that you need and then call session_write_close() BEFORE you doing the time-consuming thing. If you need to write to the session afterwards, just call session_start() again.