Welcome Guest, Not a member yet? Register   Sign In
How to get an email to trigger an HTTP request (or otherwise execute some function in PHP)
#1

[eluser]aidehua[/eluser]
I am developing an application that allows users to contribute content to a website by email.

My question is: how best to get the email to call an HTTP request (or otherwise execute some PHP function on the webserver)?

For an example of this working in practice, see the Blogger blogging platform. You can send an email to a designated email address, and Blogger will convert that email into a post on your blog.

The obvious way to go would be to use something like the pop3class on http://www.phpclasses.org/browse/package/2.html

This gives your PHP script access to the contents a POP3 server. No problem then, in principle, to get the email contents and add it to your database or do whatever you need with it.

But when do you run the script? You could say "on demand" - whenever a user wants to view the data, the script runs to check for new messages on the POP3 server. But if the POP3 server is slow to respond, that could give unacceptably slow page load times.

Alternatively, you could run the script as a cron job every n seconds, avoiding the need to query the POP3 server "on demand" while the user is waiting.

But both these approaches rely on relatively inefficient "polling" of the mailserver, whether or not there is a new message waiting.

(For this particular system, we envisage ~1 message/hour, rather than one message per second: it seems inefficient to be polling every 10 seconds for a once-in-3600-seconds event; but I don't want to poll only once every 10 minutes because that would create a delay of up to 10 minutes before new messages appear.)

Does anyone

(a) have any comments or suggestions on the above approaches

or

(b) know of a "push" approach, that would enable an email to be "pushed" to the webserver (perhaps as an HTTP POST request?) as soon as it arrives on the mailserver?

Grateful for any ideas.

Thanks,

Ed


Messages In This Thread
How to get an email to trigger an HTTP request (or otherwise execute some function in PHP) - by El Forum - 11-24-2009, 06:30 AM



Theme © iAndrew 2016 - Forum software by © MyBB