i have a php function that dispatches a certain post to all the users concerned about that post.
since sometimes there might be up to 100 000 users concerned about that post. it means that this function needs to be repeated 100 000 times thus it will take forever.
i wanna know if there is a way to run the iterations in the background but at the same time, the user who posted the answer doesnt have to wait all that time.
i’m thinking about just telling the user that the email was sent to all the users and instead of waiting till all the posts were sent just run another script in shell in the background from php.
do you guys think it’s the best solution. and if not, whats the best way to do all the processing in the background ?
thanks
Move your background task into cronjob.
It could be something like this:
UPDATE
Actually, there is another trick:
users_tobenotifiedtable.you have PHP script as cron that will read on that table and generate text files in some directory called
/data/cron/tobenotified. This file contain something like this:/data/cron/tobenotifiedand read each files and then process it.