dongxinjun3944 2012-02-29 17:23
浏览 83
已采纳

使用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

  • 写回答

1条回答 默认 最新

  • dongyin8009 2012-02-29 17:31
    关注

    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.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 不同尺寸货物如何寻找合适的包装箱型谱
  • ¥15 求解 yolo算法问题
  • ¥15 虚拟机打包apk出现错误
  • ¥15 用visual studi code完成html页面
  • ¥15 聚类分析或者python进行数据分析
  • ¥15 三菱伺服电机按启动按钮有使能但不动作
  • ¥15 js,页面2返回页面1时定位进入的设备
  • ¥50 导入文件到网吧的电脑并且在重启之后不会被恢复
  • ¥15 (希望可以解决问题)ma和mb文件无法正常打开,打开后是空白,但是有正常内存占用,但可以在打开Maya应用程序后打开场景ma和mb格式。
  • ¥20 ML307A在使用AT命令连接EMQX平台的MQTT时被拒绝