Best Time/place To Invoke Xml Parsing


My application receives HTTP POST requests with XML data.

Currently, my controller reads these requests and stores the raw XML in a table in the database (to be sure), but they also need to be parsed.

Since I don’t want to keep the sender’s computer waiting for too long, I want to send a response and then parse the file.

I see two options:


[*]Do the parsing in a separate console script, which I invoke using exec()

[*]Use the afterAction event in my controller.


afterAction seems cleaner to me, but I have no idea how/where to implement it. Any suggestions?


Okay, I decided to combine both approaches: I use the afterAction method in the controller receiving the data, to trigger execution of a console script:


	 * @inheritdoc


	public function afterAction($action, &$result)


		if($action->id == 'xml') {

			exec('php ' . realpath(Yii::$app->params['rootPath']) . '/yii scriptname');


		return true;


Does this make sense?

I usually make a most basic queue. Save the workload to the db and mark it as new, run some crontab task to process the workloads and mark them as such.

If you need it to be more responsive you could notify some service about new workloads to fire up a worker to process it.

In your case, running a command via exec() could equal to notifying a service. If it somehow fails you can always query for unprocessed workloads.