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开发者_如何学C 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?
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.
精彩评论