I am currently using pubnub chat in one of the my application. And now I want to add functionalities like on each and every chat message I want to send mail,same as upwork website is doing.
For the same I have contacted pubnub support but they are not providing any such feature, So I need to send mails from my end, mostly by calling ajax and send mail from php.
But the major issue here is as its chat feature may I need to send number of mails (mass mail) in very short time. So my server doesn't supports it.
So how to implement mass mailing.
Check Out PubNub BLOCKS
PubNub BLOCKS is a set of customizable microservices that give
developers a simple way to add code and deploy features for realtime
apps. PubNub BLOCKS execute business logic directly on the data
streaming through PubNub’s network without splitting it off to an
intermediary server controlled by the customer. This revolutionary
approach streamlines app development, reduces endpoint-to-endpoint
latency, and allows apps to better leverage the enormous scalability
of PubNub’s Data Stream Network.
Sending email (or a Tweet, SMS, etc) with every published message, or only messages with an attribute such as email=true, is something that will be implemented as a BLOCK that you will be able to use out-of-the-box. Custom BLOCKS can be implemented to do whatever else you need to do for every message or certain messages without your server(s) getting invovled.
With cakePHP I would suggest saving the E-Mails to be sent in a queue with a short Ajax call. This can be done with a json view. Then you can create a cron that calls the CakePHP Shell to send the mails with the standard CakePHP Mailer.
If the Mails are time-critical or you don't have access to the server (cron) you can also send the mails directly on the ajax call. The advantage of the cron is that the call (from the browser) is short and that the mails (depending on the server) might need more time to be sent.
Here is an answer that might help you implementing it.
Related
I need to develop a realtime notification system. Load won't be high, about a dozen of events per hour. But I just want to make it scalable for future development.
My application is written entirely in PHP.
I have found different ways of implementing real-time applications. And I think the following architecture is quite simple and have a lot of benefits.
But I want to use the Faye library for implementing real time notifications, because it has fallbacks, and generally I am not going to use Websockets because my load is really low, and at first I will stick to the long-polling mechanism. Faye provides a convenient way for disabling and enabling different transport protocols.
Here is how my architecture is going to look
However I have one question regarding communicating back from a client.
Consider the following case.
Client loads a page through plain old HTTP request to a PHP app
Client side script opens a websocket/long polling connection
Another person sends notification via posting it through a simple AJAX request
This notification is saved to a database and assigned to a target recipient.
Notification is posted to a Redis database and consumed by Faye
Notification is sent to a client, everything is fine.
So far so good, but I need to some sort of back communication, for example when a client dismisses an event.
How should this be implemented, should I send this action back using Faye or this should be sent directly to the PHP application. In case of sending an event back using Faye I need to notify my PHP application that an event was seen and dismissed. Of course I can use the same database from a Ruby application as used by PHP app, but this makes these two application coupled.
Could you suggest a right way to implement this ?
I have a project were I am required to add push notification for Cordova AngularJS Push Notification using PHP on server side which gives JSON array as output. I can implement chat etc using this, but I want to know how to implement it in push notification or accessing native app API. Firstly I thought using Javascript SetInterval, but it slow downs the app, and checks the API everytime...
For Cordova push notification you can take a look here:
http://phonegappro.com/tutorials/apache-cordova-phonegap-push-notification-tutorial-part-1/
Still, let's review some other methods of sending data to the client using Web APIs:
Long polling - keep the connection open on the server side with no or long timeout, and return a result when you want to send a push notification.
Use WebSockets - open a steady TCP connection to the server and transmit messages in both directions (unlike HTTP's request/response model).
Use PushManager - this is an experimental technology that is not yet supported on mobile devices, so I guess this is a no-go for you.
Use simple polling - every now and then poll the server for a new message.
Long polling and Web Sockets will overload the server if you'll have a lot of concurrently open connections, so I wouldn't go there. Also Web sockets are mostly used for communicating between clients (server passes the client info to both clients, then they can communicate on their own without the sever intermediating between them).
PushManager is too new a technology not yet supported in mobile.
For what you want (mobile I guess, as you want to use Cordova), and without knowing what you are actually trying to achieve, I would say go with #4. I understand you already tried it, but perhaps try to lower the polling rate to every 30 seconds or so.
I understand that while debugging it doesn't seem nice to send something from the server then wait the better part of a 30 seconds period until it appears on the client, but if you think of it from the user's view point you'll see that the user doesn't know when the server sends the data, so it does appear immediate.
However, if you're writing a chat client, then I would go with web-sockets, using the server to connect the two (or more) clients in the chat and letting them pass the messages directly. If you want the chat to be server backed, just periodically send the transcript to the server using simple AJAX.
DIY vs Hosted Realtime Data Stream Network Service
If you do not expect to have more than a few thousand clients using your app, the DIY (do it yourself) sockets technologies (WebSockets, Socket.io, etc) is feasible. Beyond a few thousand (many of our customers say in the range of 5 to 10 thousand) you will experience difficulty (and large expense on server resources and scalable code) scaling your service.
Using a hosted realtime data stream network service like PubNub, Pusher, Ably, etc will be less costly and complex and it will just work. With some of the hosted services (PubNub for sure - which I work for - full disclosure) provides the ability to publish the message in realtime and include a push payload (for GCM, APNS and MPNS) that will also send the push notification if the app is in the background or not running.
With PubNub BLOCKS, you can also implement server side code that runs in the PubNub Network to inspect, manipulate or process the message without having your server do the work. This means you could send the message to other third party services: translate message to another language, use AI services for whatever reason, send an SMS/email/etc and much much more.
What is the best way to set up a system that checks for events daily and sends messages via email, Twitter, SMS, and possibly Facebook? Keep in mind, that I do not have access to a web server with root access (Using Rackspace Cloud). Would PHP have a solution for this? Would there be any drawbacks to using Google App Engine and Python?
If you are using Google App Engine with Python you could use "Cron" to schedule a task to automatically run each day.
GAE also allows you to send emails, just a little tip: make sure that you 'invite' the email address used to send mail to the application as an administrator so that you can programatically send emails etc.
Using php I'm trying to figure out the most efficient way to design my web app to incorporate 3rd party API's. The user of the app does not need to see the response from the api call.
So for instance a user will click to send maybe 1000 emails. Those emails will go via someone like SendGrid or Amazon SES. The user does not need to wait until those emails have been processed. Essentially I want those processed in the background with the user returned to the web app.
Should I be thinking of using a queuing service like SES
I have at least three api's I am incorporating.
Thanks
The most probable way is running some background processes and sending them messages via some queuing solutions like RabbitMq (see also the SlideShare presentation for details). You may also consider using Gearman for distributed computing: make GearmanClient::doBackground() calls from API wrappers, run Gearman job servers as middle points and run workers that actually will make calls to your APIs. See some presentations for further details.
Is there any way to trigger a php script when a new email arrives on Google Apps (Gmail)? I've figured out a way to poll the inbox to look for new messages, but I'd ideally like a more event-based solution. Basically I need it to be run from a server somewhere which would parse new email messages and process itself according to the contents of the message.
Most mail transfer agents let you put in filters that can process incoming mail through a program as it arrives. SpamAssassin works this way, for example.
Because Gmail is hosted, you can't exactly do that.
The only realistic answer in this case is polling. Thankfully Gmail exposes both POP3 and IMAP access, so checking should be very simple. There are a few comprehensive mail reading libraries out there, or you could be insane and poke at IMAP directly.
Edit: Because you're on Google Apps, there's also an Atom feed of unread messages, though you'd still need something to poll the feed, unless you happen to have something handy that will do the polling for you and fire up requests. I vaguely recall something like this existing, but I don't recall what it's called...
It's possible now, using Google Apps Scripts. You have to create a script and attach a trigger to it to run every 1 minute or so. If a new email is found, just invoke your URL.