Question

I'm developing a Rest service. Some external system sends me an XML file which I parse, load data in DB and after that send response - 'scope of concrete object that has been loaded'.

The problem is that parsing and add data to DB takes large time and external system gets timeout error message. I would like to send response immediately by parts when parse incoming XML:

1millisecond - Object one has been loaded 2millisecond - Object two has been loaded

class ImportController extends Zend_Rest_Controller{

   Zend_Controller_Front::returnResponse(true);
   $this->getResponse()->setHeader('Content-Type', 'text/html');

   foreach($xml as $xmlElement){
        DbClass::addXmlData($xmlElement);
        $this->getResponse()->setBody('Another object has been loaded');
        $this->getResponse()->setHttpResponseCode(201);
   }
}
Was it helpful?

Solution

Once you've sent the response you can't keep sending it. You'd have to have multiple requests. Multiple responses to a single request is bad practice.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top