how to trigger a function on defined date - php

i am doing a project where i need to notify a user through email if his account has expired,
that is when a user signsup his sign up date and expire date is inserted into the database
now what i need to do is , i need to fire a function when the users expire date is passed
and send an email notifying user about the expiration of his account .
and this needs to be done automatically through the function .
how can i achieve this ?

The simplest thing to do is create a basic cron job that runs on a regular interval (like hourly or daily) that runs a PHP script that queries the database for any newly expired users and then emails them.

You can have a cronjob that runs every hour or so (or quicker if you need to). This cronjob would run a PHP script that gets a list of all expired accounts and sends emails to them.
Here's a tutorial on how to use crontab.
Here is a SO question on Cronjob and PHP
Getting started with cron jobs and PHP (Zend Framework)
Timed Tasks (cron-like) in PHP
PHP: running scheduled jobs (cron jobs)
What is the best method for scheduled tasks in PHP

Write a cron job (running as often as you think appropriate) to call a script (possibly PHP CLI) that does a select for all expired accounts and mails them. And what does this have to do with JavaScript?

Probably the easiest way to do this would be using either at or cron. Either one of these could be set up to call a PHP or whatever script at the time of expiration, or it could be just run once an hour, each time checking if there are any newly expired entries.
A less efficient approach would be to have the header or footer script of your pages to check the database every time any page is loaded, but I would not recommend this approach unless you absolutely can't use cron or at.

By the way, if you are not using a unix / linux system but a Windows one, you could use Scheduled Tasks and call a script.

Related

php function to schedule execution of a task at a certain time

I want to create a web based app, written in PHP that work like a reminder app, so the user enters a line of text and a time to reminded, app gets these two and at the specified time reminds the user. I implemented the program completely, but for scheduling, I have a problem: the program should do other jobs in between setting reminder and reminding user, but the only function that I find that can do something similar is sleep(), but it seems that sleep() is not the best choice because in between setting the reminder and reminding the user, the program could not to do anything.
Is there a function in php that enables scheduling tasks and at the specified time, the PHP program runs the task.
I do not want cron, crontab , scheduled task or any other OS-dependent solution.
It isn't possible to execute a task at specified time in PHP only.
You may create a condition comparing current time with the time the task should be executed and run it on every request, but that doesn't guarantee the execution at the exact time, since there may be no user requests at all.
This is what cron is for.
This is not possible in PHP.
You may check if your host provide a cron-like option (mine provide an URL call scheduling).
Another option, if users are always connected to your web app, is to manage alerts in javascript and/or ajax.

How to automatically call a php script every day to send out automatic emails

Is there a way where I can automatically call a php script after a specified interval.
I have a php script(say remindusers.php) that uses mysql to query a database where people have submitted their weekly reports. This script automatically queries the database and sends an email reminder to people who have not sent in their weekly reports yet.
What I am now supposed to do is give the ADMIN an option to set a reminder start and reminder end date during which calls should be automatically made to my remindusers.php script and cease on reminder end date.
What I learnt from SO/google is that I can setup cron (in LINUX) to automatically call my remindusers.php, but I dont have any shell access to do this.
Else Can I write another php script to essentially sleep every 24 hours and automatically wake up to call my remindusers.php script.
Are there any other built-in methods ?
Any ideas?
Use your site's visitors to trigger the event. Send a message and then check if 1 day elapsed. Then send another. You still need to pay attention not to double/triple/... send deu to synchronization.
When the time has elapsed use a MySQL (or system) MUTEX to ensure only one send occurs.
Yes you can! What you need to do is to use cron jobs. Cron jobs are essentially telling the server to execute a script (PHP or otherwise) at regular intervals. Cron jobs are very powerful and customizable, as you can set virtually any interval for your cron.
If you are using CPanel to manage your site, there is a button in CPanel to view all the cron jobs you have set. There is also a tutorial on that page.
Hope this helps.
Try with this PHPCron
PHPCron is a simple PHP script which lets you run multiple tasks on a schedule or timer. It can be run either from the command-line or via a web browser. Its behaviour is very similar to the popular cron program for UNIX.
http://katyscode.wordpress.com/2006/10/17/phpcron-running-scheduled-tasks-from-php-on-a-web-server/
I understand that you don't have Shell access but have you had a look at the cPanel to see whether there is an option to setup a cron job in there?

Configure Scheduled Task in wamp Server [duplicate]

I want to schedule sending of email from php script. I want user to specify date and time and then on the specified date and time, I want those emails to be sent automatically. How do I implement it? I am working on codeigniter.
One way to do it would be to create a "scheduled_emails" database table. Put all the emails you want to queue in there, including columns such as, recipient, subject, message and optional headers.
You could then set up a script to look at that table and send any emails that have a "send_time" which is greater than the current time. You could then set up a cron job to run this script every.. 5 minutes for example.
PHP usually uses an external scheduler for this sort of thing. That means cron on *nix or Windows Task Scheduler on Windows.
If you want to set it up through a web interface, then you might consider storing your schedule in a database and having cron (etc) kick off a script that looks for overdue emails every 5 minutes.

Send mails with PHP regularly at a specific time

I have three mysql tables; Users, Tasks and Task_Users, where each user can create their tasks through a web application I'm developing in PHP.
The thing is, I want my application to send an email to the users one day before the task occurs. The first thing that came to my mind was to do a MySQL job or trigger to send the email but I dont have an idea of how to do id,
What would be the best way make this happen or how could I call a job through PHP and execute it every day and verify that there is just one day left before the taks ocurrs and then if that is true send the email?
Here's my table definition. Thanks in advance.
Users
----------
UserId,Names,email,pass
Tasks
------------
TaskId,TaskName,Descripcion,TaskDateTime
Tasks_Users
------------
TaskId,UserID
You can write a CRON Job for this.
What's CRON Job ?
Cron is the name of program that enables unix users to execute commands or
scripts (groups of commands) automatically at a specified time/date. It is
normally used for sys admin commands, like makewhatis, which builds a
search database for the man -k command, or for running a backup script,
but can be used for anything. A common use for it today is connecting to
the internet and downloading your email.
What do you have to do ?
Just write a normal PHP script. make one that will work if it's launched directly from the browser. Then schedule that very same PHP file to run in cron, using this as a guide:
How to run a CRON Job after it's written ?
http://www.inmotionhosting.com/support/edu/cpanel/301-run-cron-job
If you have any issues let me know.
I'd make a cron job that regularly runs a script (say every 5min?) which checks for tasks that need emails sent. Then the script script sends the necessary emails.
*/5 * * * * php /path/to/script.php
Would call script.php, which checks and sends emails, every 5minutes.
Some info on cron is here:
http://www.pantz.org/software/cron/croninfo.html

How to create a always running PHP background script to clean up particular rows in mySql DB?

How to create a always running PHP background script to clean up particular rows in mySql DB?
Hi guys I want to create a PHP script that automatically keeps on running (for example after every hour) and delete some particular rows from database(for example user comments those are atleast 5 days older)for this I am already having the date column in table.
Please guide me how to do this as I am new to PHP.
For this, you can create a cron job, if you have access to the cpanel....
The cron jobs will run periodically, say for every minute, hour, day or week. Refer this
what you are looking for is information on running some php maintenance scripts as a cron job. How you do that will depend upon what type of server you are using, if you are using shared hosting or have a dedicated server. In shared hosting there will be information about this on your control panel, otherwise you need to talk to your server admin.
You can set your PHP scrip that cleans up the mySql DB to run every hour or every mins/week/months with cron
crone job basic

Categories