等待 PHP 页面在后台处理完 SOAP 请求,然后执行下一条语句?
我有向远程服务器调用 SOAP 请求的 PHP 代码。远程服务器处理 SOAP 请求,然后我可以获取结果。
理想情况下,我想调用 SAOP 请求,等待 5 秒钟,然后去查找结果。原因是远程服务器需要几秒钟才能完成处理。我无法控制远程服务器。
目前我有这样的代码:
$object = new Resource_Object();
$identifier = $_GET['id'];
$object->sendBatch($id));
sleep(5);
$results = $object->getBatchReport();
echo $results;
上面代码的问题是sendBatch需要几秒钟才能完成。添加 sleep(5) 后,页面加载时间延长了 5 秒,但结果仍然不显示。如果我再次加载页面,或者从另一个页面调用 getBatchReport(),结果就在那里。
我想这与 HTML 的无状态性有关,导致整个页面立即执行。我考虑过使用“输出缓冲”,但我不太明白输出缓冲的用途。
我还考虑使用 jQuery 和 Ajax 持续轮询 getBatchReport(),但问题是我需要从另一个位置调用此页面,并且随着 sendBatch() 的增长,5 秒的延迟可能会增加,大概2分钟左右。如果我远程调用此页面,我认为 Ajax 不会起作用(此页面已在由 /dev/null 2>&1 & )。
我无法控制 sendBatch 例程中指定的远程服务器,并且据我所知它没有任何回调函数。我不想使用 CRON,因为这意味着我必须一直查询远程服务器。
有什么想法吗?
I have PHP code that calls a SOAP request to a remote server. The remote server processes the SOAP request and I can then fetch the results.
Ideally I would like to call the SAOP request, wait 5 seconds, and then go and look for the results. The reason being the remote server takes a couple of seconds to finish it's processing. I have no control over the remote server.
At present I have this code:
$object = new Resource_Object();
$identifier = $_GET['id'];
$object->sendBatch($id));
sleep(5);
$results = $object->getBatchReport();
echo $results;
The problem with the above code is sendBatch takes a few seconds to complete. After adding sleep(5) the page take 5 seconds longer to load, but still the results are not displayed. If I load the page again, or call getBatchReport() from another page, the results are there.
I guess this has something to do with the statelessness of HTML that is causing the whole page to execute at once. I considered using 'output buffering' but I don't really understand what output buffering is for.
I was also considering using jQuery and Ajax to continuously poll getBatchReport(), but the problem is that I need to call this page from another location and as sendBatch() grows the 5 second delay might go up, probably to about 2 minutes. I don't think Ajax will work if I call this page remotely (this page is already being called in the background spawned by
/dev/null 2>&1 &
).
I have no control over the remote server specified in sendBatch routine and as far as I know it doesn't have any callback functions. I would prefer not to use CRON because that would mean I have to query the remote server the whole time.
Any ideas?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
当我认为 5 秒就能完成这项工作时,我过于乐观了。经过重新测试,我发现实际上 15 秒是一个更现实的值。现在正在工作。
I was overly optimistic when I thought 5 seconds would do the job. Upon retesting I found that actually 15 seconds is a more realistic value. It's working now.