tags:

views:

134

answers:

6

I'll be writing a script to parse text documents into a MySQL database. I'll be converting PDF's to text with a separate utility. These PDF's will be submitted via e-mail attachments.

I'm looking to see if I can do this with PHP since that's the server language I'm most familiar with. Second choice would be Perl, but I'll take your recommendations.

So the language needs to be able to:

  1. Check an e-mail account for e-mails with attachments (every few minutes, or so).
  2. Save the attachment.
  3. Parse the file (looking for contact information) using Regular Expressions.
  4. And place the results in a MySQL Database

I won't have full access to the server since it'll be hosted by GoDaddy or similar.

I'm familiar with PHP but I can't think of how I'd have it systematically check a mailbox. If PHP can't do it, are there languages that run constantly on a server performing tasks without requests from a browser?

Thank You.

+7  A: 

You can do it with a PHP script, managed via a cron job.

Jonathan Sampson
Cron is the way to go, then it doesn't matter whether it is PHP, Perl or even sh.
Jay Zeng
+2  A: 

You can trigger the HTTP requests regularly using a service like http://www.setcronjob.com/

infamouse
A: 

Check this baby out - http://www.iamjacksdesign.com/blog/check-pop3-email-with-php/ - there's also http://www.php.net/manual/en/ref.imap.php

You can use cron to run your e-mail check script regularly - http://www.codewalkers.com/c/a/Server-Administration/Introduction-to-crontab/

gabrielk
+1  A: 

Cron Job is the way to go. Also, if I may make a recommendation, make certain to place the PHP script out of a web accessible directory and run it via CLI php.

If your script is placed in a directory that is accessible from the web, it's possible that it could run more often than desired... especially if a bot/crawler gets hold of it.

nategood
Thanks. Good Idea. Would it be acceptable to place the file in a folder with an .htaccess set to Deny From All?
Andrew
Yes. That should suffice. Also changing the permissions of the file so that in your case apache can't access it would work. Change owner and permissions st only the user running your cron jobs can execute it.
nategood
A: 

Similiar question here.

Jrgns
A: 

PHP itself cannot perform tasks by itself without a client request.

The common way to to use cron job to schedule run scripts (shell, perl, PHP, python.. etc).

If you are running on IIS, then you can use Schedule Tasks in Windows.

rockacola