I'm developing website that will send email back to user automatically when they registered to my website. I have searched from internet, most of them said that i have to used cron jobs; the big problem foo me now is about cron jobs. I don't how to write it and also how to execute it. Can anyone gives me some example about it?
Thank in advance.
If we assume that the script that you want to run is located at /home/me/myscript.php then all you need to do is create a cron job that will run that script every minute.
Several hosting companies have an interface (cPanel for instance) that will allow you to add a cron task easily. You can also add the cron task by editing the relevant cron job and adding:
*/1 * * * * /usr/bin/php /home/me/myscript.php > /dev/null
If you are wanting to send a confirmation email to the user once they have registered, you can use php mail function to do this.
http://php.net/manual/en/function.mail.php
You can create a PHP file which has a heartbeat event. You put that to sleep using the usleep function with the desired time interval and you can have a list of tasks to be executed (heartbeat tasks), knowing the time rules (when they should run, how often, and so on), and your heartbeat.php will check after each usleep which tasks should be executed and execute it. You can run this heartbeat.php on your server.
However, I do not see the reason why do you need a cron job, heartbeat or any periodic solution. Why don't you send the emails using php functions exactly when you need to send them?
Related
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?
I'm developing website that will send email back to user automatically when they registered to my website. I have searched from internet, most of them said that i have to used cron jobs; the big problem foo me now is about cron jobs. I don't how to write it and also how to execute it. Can anyone gives me some example about it?
Thank in advance.
If we assume that the script that you want to run is located at /home/me/myscript.php then all you need to do is create a cron job that will run that script every minute.
Several hosting companies have an interface (cPanel for instance) that will allow you to add a cron task easily. You can also add the cron task by editing the relevant cron job and adding:
*/1 * * * * /usr/bin/php /home/me/myscript.php > /dev/null
If you are wanting to send a confirmation email to the user once they have registered, you can use php mail function to do this.
http://php.net/manual/en/function.mail.php
You can create a PHP file which has a heartbeat event. You put that to sleep using the usleep function with the desired time interval and you can have a list of tasks to be executed (heartbeat tasks), knowing the time rules (when they should run, how often, and so on), and your heartbeat.php will check after each usleep which tasks should be executed and execute it. You can run this heartbeat.php on your server.
However, I do not see the reason why do you need a cron job, heartbeat or any periodic solution. Why don't you send the emails using php functions exactly when you need to send them?
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 develop a schedule task system like the one used by Wordpress to schedule post? Do they use Cron Job? If they use it, how they configure it through PKP script?
As far as I know, WordPress just sets the publish date to some time in the future. It doesn't actually cause an event to happen in the future, it just looks that way when someone views the site.
You'd need a cron job if you actually wanted to do something in the future, web servers only respond to requests made by user agents.
Use cron and in iterations get run php_cli interpreter with your script.
I use php cron tasks, they look like the following
0 0 * * * * php -f /var/www/public_html/mycronphpfile.php
This means, at midnight, every day, run the command line php and execute the specified file.
i managed to send multiple emails (check here).i am stuck with sending automated emails via cron.
This is what i need - while the admin send emails, i store the message, emails, event date in the database. now i am trying to set a cron job to send emails to all these ids from the table with the message i have as a reminder. i am not familiar with cron job scripting, can anyone help in guiding me the right way to write script that i can place in cron tab. I am planning to send two mails - one day exactly before the event and on the day of event.thanks
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:
http://www.unixgeeks.org/security/newbie/unix/cron-1.html
Basically, using the values at the beginning, specify the schedule (minute, hour, day of week, day of month, etc.). Then set the user it runs as, which is likely to be "apache" or whatever your web server daemon is running under. Then set the "command" that cron is running to be php php_email_script.php (where "php_email_script.php" is the name of your PHP file.
30 minutes and still no answer, here's a few open doors:
cron reads it's rules from system-wide /etc/crontab, or from you personal crontab which you edit with crontab -e
cron takes a format where you say on which minute / hour / day / month things should happen, use google or man crontab for the format
cron has the amazing side effect of mailing the output of the command to the user owning the crontab
Now you are stating that you're using php. The easiest way to get some php running from cron, is to issue a wget -O - -q http://yoursite.com/yourprocessingscript.php?verysecret=123123 and have an appropriate processing script on yoursite.com. (you may want to let that script check $_SERVER['REMOTE_ADDR'])
So in short, if you just put the right magic in /etc/crontab, like
0 0 * * * jay wget -q -O - "http://yoursite.com/processmidnight.php?secret=yes_very"
and have your script produce some sensible output, you will get a mail delivered to local user jay, which you may want to forward.