Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Monthly Job?

Status
Not open for further replies.

bam720

Technical User
Sep 29, 2005
289
US
Im not sure if this should go here or in mysql or anywhere else. What I am looking to do is email a user 30 days prior to their account expiring. I just want to be able to run through the database monthly. Is there a way to have this automatically done with a php script, or should I be looking into mySQL functions or something else? I hope this makes sense of what I am trying to do. I just need some direction to head in :)
 
First, you need a mechanism for running a PHP script periodically. On unix-like OSes, that'll be cron; on Win32, probably task manager.

Then you have the automation tool invoke PHP from the command-line and run your script.

That script will send emails to the appropriate people in your database.



Want the best answers? Ask the best questions! TANSTAAFL!
 
OK I know I have a Cron manager in my Cpanel. How do I call php from the command line? I have never done this before. Will my php page be just a connect to DB call, exectue a SQL Query and then email the apropriate results? I appreciate the quick response and the help :)
 
From the command-line, you should be able to issue:

/path/to/php -q /path/to/script.php

to run a PHP script.


Yes, your script will connect to your database, fetch some user information, and loop through that information, sending an email to each user on each iteration of the loop.



Want the best answers? Ask the best questions! TANSTAAFL!
 
The php method didn't seem to work for me, so I found this to work instead.
Code:
wget -q -O /dev/null full/url/here/filename.php
 
The PHP method only works if PHP is installed as CGI. If it is an Apache module command line PHP won't work.

Your solution is ok, but anyone could trigger that script through the web - unless you have taken precautions in the script to allow execution only from e.g. the IP of the host or restricted (if Apache) using a .htaccess file.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top