tags:

views:

69

answers:

4

May be it's a stupid question, but i didn't find unswer. I use a web-hosting startlogic.com. i asked employee about cron. They told me that they only have a feature in the control panel called "Schedule jobs" where i can manually put job. But i need to do this from my web-application. For example, when i push button, i will receive a email notification after 1 month. How to implement this using php? Can my web-hosting provider do this or i need to change provider (if yes, what will you recommend?)

Thanks in advance.

+2  A: 

You could have one PHP script, that gets run say once an hour. In this script you could then implement your own cron-like functionality, say reading a database of cronjobs and executing them.

eliego
Can you wirte a code sample please.
dsplatonov
Work it out yourself, or ask another question. SO isn't a place to get your code written by others.
Skilldrick
A: 

If you don't care about the exact time, you can check with each pageload (or every first an hour) your database, if there are jobs that need to be executed.

This way the cron will not be executed exactly after a month, but with the next page load after a month, which will most likely occur soon.

JochenJung
The OP has access to cron functionality (Schedule jobs) - he just doesn't know how to use it to send email notifications.
Skilldrick
+6  A: 
  1. Make a PHP script called cron.php (outside of your web root if possible).

  2. Set this to run regularly under "Schedule Jobs"

  3. Every time cron.php runs, it checks a database of jobs to see if any are due yet.

  4. If any are due, they are run.

  5. Once run, they are marked as such.

  6. To add new jobs to the list, just add a new row to the database with the details of the job and the due date.

Skilldrick
+1 The OP should go with the scheme anyway, regardless of the feasibility to automatically schedule "physical" cron jobs. You don't want to have potentially thousands of jobs scheduled for one-time execution that may be wiped out by a server re-install/move/crash.
deceze
thanks. How to create job in database? Any samples or links
dsplatonov
Jesus. Here's a link to show how to create a job in a database: http://www.w3schools.com/php/
Skilldrick
+1 Though I would add a step between 4 and 5, to mark the running jobs as "running" before they are actually run (might be handy if the server crashes while some jobs are running).
wimvds
@Skilldrick Man, where is the exact tutotial about creating cron job in database? You gave link to php tutorial.
dsplatonov
I think you need to learn PHP. It's not difficult to add a record to a database.
Skilldrick
You might find this useful as well: http://www.w3schools.com/sql/ Seriously though, everything you need to know to do this is contained within these two tutorials.
Skilldrick
@Skilldrick i know how to add a record to database. I need to know what must contain this record
dsplatonov
@dsplatonov: you need a timestamp which is the due date (today + 30 days or whatever) and you something that will tell your code what to do, such as an instruction id, and maybe a parameter, such as email address. So an id of 1 could map to a `send_email` function, which would take the email address in the other column. Use your imagination!
Skilldrick
great - that is what i'm searching. Thanks
dsplatonov