Yii Framework Forum: Best Time/place To Invoke Xml Parsing - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

Best Time/place To Invoke Xml Parsing

#1 User is offline   DocSolver 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 36
  • Joined: 12-December 12

Posted 25 November 2013 - 11:29 AM

Hi,

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?

Thanks!
0

#2 User is offline   DocSolver 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 36
  • Joined: 12-December 12

Posted 25 November 2013 - 12:57 PM

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?
0

#3 User is offline   nineinchnick 

  • Master Member
  • PipPipPipPip
  • Yii
  • Group: Members
  • Posts: 622
  • Joined: 12-September 11
  • Location:Bialystok, Poland

Posted 25 November 2013 - 01:07 PM

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.
Don't be a dick.
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users