Should I Use Laravel Queues With Ajax For Sending Bulk Emails? - php

I am developing a Laravel application that uses ajax in making requests. This application needs to send bulk emails. I have read the documentation on Queues and understand basically that it'll help run jobs at the background. What practice do you think will be best?
Should I send the emails via an ajax request while not freezing the user?
Should I use Laravel Queues alone?
Should I combine both?
My current thought:
If I use just Queues I might face difficulties updating the user on the progress of the task.

I recommend to use queues whenever you are performing bulk actions like sending emails, sms, notifications, etc. This will better your user experience since they won't have to wait (freeze screen) and move onto other tasks.
Should I send the emails via an ajax request while not freezing the user? Yes
If I use just Queues I might face difficulties updating the user on the progress of the task.
That is correct. You won't be able to show progress. Rather you can show appropriate message to the user like 'emails sent successfully' and let the queue jobs do the rest of the tasks for you.

Related

Trigger Slack Bot by Direct Message

I'm realy new to this Bot stuff.
I want to create a simple PHP-Skript that is sending an answere every time the Bot is contacted by a user via Direct Message.
I read the Api-Docs but the only thing I found was the /-Command.
Currently I have a Cronjob thats checking the RTM-Api for new messages.
I think there must be a better way then running a Cron-Job every few seconds to check if there is a new message for the Bot.
I found the "EmojiBot" that is exactly responding in the way I want.
Using the RTM API to build a bot will work, but there is indeed an easier way: Use the new Event API from Slack.
The Event API allows you to subscribe to range of events. When the event happens, Slack will automatically call your php script. So you don't need to run a CRON loop. This also works with bot users and direct messages to bot users.
Check out the Event API documentation for details.
You can use Botonomous Framework which supports Events API. You should subscribe to the events, then update the framework configurations which is explained here. Finally you have got a nice event object and based on certain criteria you can send a message back to a Slack channel.

Firebase chat notifications via PHP to SMS + EMAIL

We have firebase chat application (check any chat example or tutorial) that will have same copy as our.
We would like to sent email notification or sms message, if user hasn't seen the chat message yet.
We can connect to firebase database with php and check all the messages, if they are seen or not. but It's not really proper way of doing it.
Does anyone have idea how we can implement that, so we can track of all the messages and if they haven't seen it, then sent the email / sms notification based on user preference?
I just want to know how we can do that with firebase. if it was just php and mysql. it was really easy to do this.
Not sure if this can be done efficiently in Firebase. You will have to setup a cron job to fetch the messages which are not seen and trigger SMS/Email fallback.
I would recommend using Applozic (https://www.applozic.com) for Chat related stuff and Firebase for storing user meta data and other data.
Applozic provides a single click configuration to enable Webhook/SMS/Email fallback, along with that you will get all the whatsapp like chat features along with full UI with no need to write any additional code.

How to implement dynamic chat application in Ios using php, Something related to Skype like application

I am trying to implement a chat application in IOS. In general We use two php files one for posting a message(sender) another for retrieving the message(receiver).
I want to accomplish the following:
Consider A(sender) and B (Receiver).
A sent message to B. And A is waiting for B's reply. So i need to call post-api.php for sending a message and at the receivers side(B) i need to retrieve using getapi.php
when B reply to A it must automatically appear in my inbox(live chatbox) of A, without calling getapi.php. I know this scenario is not possible. But is there any solution or method so that my chat application works like skype or facebookchat.
There is multiple way to implement the chat functionality.
Polling: Send request to server and process the response from the server in timely fashion after a particular time interval using NSTimer(But remember is will cause the battery drain).
Using APNS: Using the official Apple push notification implementation, whenever there is new entry in chat table on server side send the notification to particular device using push notification and handle the notification using the delegate methods (Although not 100% reliable).Using Push Notification
Using Socket Programming: Using the socket programming you can have dedicated connection between client(device) and server. I have provided the link having the source at the end of the tutorial.Using Socket Programming
As you know that without getapi.php it is not possible to update chat list so you need to make management something like: you need to use NSTimer and with the help of timer you need to call your getapi.php service after certain time interval let say after 2min so that chat can be refresh and user get the reply this is the only possible way at my knowledge.

How shall I setup user event notifications in my code?

I'm coding a team collaboration web app in PHP, and I have a few events that users get notified about through email and/or SMS. The current way I'm doing it is as follows:
Every user has his notification settings in the database as boolean variables.
Say users would be notified when someone comments on the team's page. When the function that posts a comment is called, the same function would contain extra code that checks "who wants to be notified about this?" and then sends notifications to them (which slows down the function a bit).
Is there a more efficient/faster/flexible way to setup notifications? maybe through a script that runs via a cron job? or shall I just keep doing it this way?
I appreciate your help.
I implemented a similar method to the one you're following on a website with a multi-table approach. The users table held the contact information along with opt-in, opt-out options while an event table held the instructions to notify. Several other events were hard coded because of their importance. The thing that set the site apart a bit was a "workflow" area on the user's dashboard that also showed the user what action items they had. We found that most users ignored the emails and dealt directly with that dashboard workflow area. You'd be surprised how many times people change emails or just ignore them altogether.
With 280,000 users and daily visits in the tens of thousands, there was no performance issue noticed. However, the process of queuing emails can be inefficient if you're not careful, so take particular time to benchmark your mail sending functions--its as easy as echoing out microtime before and after the mail send is accomplished--to evaluate its effectiveness. On my current company's site, such improvements yielded a 800% reduction of email queuing time (queuing being the process of generating the emails and submitting them via php mailer to the mail system for distribution)
I'd say have a table that is a queue of notifications. Let the function that post a comment still check "who wants to be notified about this?" but then just log entries containing the messages in this table. Then have a separate process work from the queue i.e. your cron job suggestion.
Depending on your database you may perhaps make use of database events or triggers instead of a cron job. This however have the requirement that your database allow you to put code in your database that will send the SMS or Email. This poses a security risk normally which you may or may not be concerned about in your setup.

Best method to send programmed emails from web application

I want to send emails through a web app, for example, reminders of a tasks manager, reminders of birthdays... I want to program a date and an hour, and get the email sent at that moment.
I think I have two options to do this: using cron or sending email with a future timestamp.
Using cron involve to run a command (which will query the database) each one, two o five minutes to check if there are any email to be sent. Or, another way, when I save a new reminder, put a new crontab task (via execute a system command from the web app) at the time indicated. With the first option, I think the server load will be excessive. With second option, I'll have hundreds of crontab tasks, what looks dirty for me.
Perhaps I could send the email at the very moment of creating the reminder, but changing the email timestamp to a date and hour in the future. I know some email servers can manage this (like Mercur for Windows), but, is it a standard? I will use my Gmail account to do this job. And, with this solution, I won't be able to cancel a reminder, because the email has been sent at the moment I created the reminder.
I can use PHP or Ruby (RoR) for server language, so the language isn't important, because both of them can send emails and call system commands. If the solution entails scripting, I can use bash scripts, Perl, Python... (the server is a Linux box).
Which do you think is the best method to accomplish the solution to this problem?
I apologize for my poor english. Thanks in advance.
I don't know if you've looked into this, but since you use GMail I thought you might be interested. Google Calendar has this feature:
Go into GMail.
At the top, click on "Calendar".
On the left is a list of calendars. Each has a small link called "Settings". Follow this link (you may want to create a new calendar for this project).
This brings up a tabbed interface. I think it always brings you to the "Calendars" tab, but if it doesn't, click that tab.
Each of the calendars will have a link next to it called, "Notifications". Click the link for the calendar you want to notify you.
This will bring up a list of settings which you can use to set up notifications by sending an email.
Google's API should allow you to access the calendar to sync it with your application. If it's set to send you an email, it will handle all the email for you.
instead of having a cron job for each reminder (or notification, whatever), you might write everything in a file and periodically (for example every 5 minutes) call a script (e.g. php-script) that reads the file and checks whether to send a notification or not...
you would have the functionality without needing to create a cron-job for every item...
would that be a solution?
regards
Having a cron is a better option then sending out emails with future date stamp. Set a cron to run on periodically and it can send out emails.
We have similar questions.
Sending mass email using PHP
https://stackoverflow.com/questions/215736/how-do-i-send-bulk-mail-to-my-users-in-a-generic-fashion
Read those you will get some ideas.

Categories