Asynchronous Script Execution Or Threading ?

[size="4"]Hi Friends, i would like to know… does Yii supports Asynchronous script execution or multi threading ?

I am in a situation of sending 4 ( to : accounting det, user, created-person, admin) emails when a user update the profile.

I am almost done with my requirement but unfortunately the php page takes too much time, more than 12 seconds to load :( which is not a good practice.

can somebody please suggest me someway of achieving this task in less time ? any help would be highly appreciated.

Please note : in each email, content is different from one another.

Thanks in advance. [/size]

anyone there to help me out ?

Long-lasting tasks can usually be processed by crontab (after updating the profile you add a task to some queue and then cron + console app do the rest).

But… 12 seconds for email?? It’s too much, you know.

Yeah i know, that’s why i am worried about.

do you have any other suggestion than a cron job to use ??

thanks for you comment ORey.

I believe that cron is the best fit for such tasks, it’s bulletproof.

So no, no other suggestion.

Hmm, seems like I have one.

Figure out what’s going on with your mailer :)

Treatment of symptoms is not the best practice.

just a php mail function is used. :(

You can create a table in which save what email to send.

As you did it, you can create a console command (read the guide about console application) that looks in this table and send the needed email.

With cron you can call this console command every 5 minutes.

I would if possible use ajax.

Ajax Request -> Send Email in PHP -> Output result -> Next Ajax Request

Hi, Thanks for your comment.

Is it possible to access a console command after submersion of a form ? also to send parameters to console command ?

[size=“3”][size=“4”]Can anybody help me pls, even if i go for a cron job i feel like it would’nt help me since i will execute the crone job in the same page as the last line.

even to run the cron job every 5 minutes, i must be able to pass values from my php class.

is there any way to pass parameters to console ?[/size][/size]

As above, Use Ajax.

Create each email in a separate ajax call.

e.g.

User Updates Profile -> Ajax request -> Email 1 sent -> Ajax request -> Emails 2 sent -> Ajax etc…

[size=“3”]Yeah nah… ajax would be great at this point… tnx tnx :)[/size]

[size=“3”]any easy way to send an ajax request for an action in yii ?? haven’t worked in ajax much.[/size]

about cron job, use a database table in which you save all parameters you should pass.

Every 5 minutes the console read the whole table (with the parameters), sends the needed mail and delete the corresponding lines.

As you see, you don’t have to pass parameters to the application.

You could just add a flag in the modified profile “should_mail_be_sent”, so you don’t need more table or any parameter, the command will read the marked records

Thanks for this as well. what do you think of ajax request ?? any idea to do with yii ??

[size="4"]any idea to write an ajax call after model validates ?? or inside an action of a controller ??[/size]

You are messing a lot, ajax is triggered from the browser, how you can trigger an ajax request inside an action?

Yeah i agree with you zaccaria. i thought of it because a person recommended to have multiple ajax requests. :(

sorry.

finally i am left with no choices other than a crone job. :(