I want to mail after 6 hours automatically to my user who hasn't fully completed form on my website.
Help Me
Use crontab -e to edit the cron table for your account.
In the crontab, put an entry something like...
0,10,20,30,40,50 * * * * /usr/bin/wget -O - -q http://path.to/cron.handler.php
or the equivalent
*/10 * * * * /usr/bin/wget -O - -q http://path.to/cron.handler.php
...which will run the cron handler php file every 10 minutes using wget (there are other options as well, and you may need to edit the command appropriately). (Note: you don't want to just run it every 6 hours, because then if someone happened to fill out the form right after it ran, it wouldn't have been 6 hours since they filled it out next time it runs, so you'd end up with 10-11 hour gaps.)
Then in your PHP file, find users who BOTH (a) haven't fully completed the form for at least 6 hours and (b) haven't been emailed yet. Send them an email, and mark them as having been emailed.
You will need to create the php script that does the checking and mailing, and then set the cron job like the following
/path/to/php -q /home/username/public_html/mycheckingscript.php
Obviously you will need to adjust the first path to point to your php binary, and the second path to point to the full location of your checking & mailing script.
I don't think you want to set the cron up using php. Instead write a php script and then have cron execute that script every hour or so. This would be something that is going to be dependent on your operating system.
For linux, here is the manpage for using crontab.
There is no way you can change/add a schedule on the cron job on the fly. according to my experience. because until now i did not find..
Related
Using PHP, I want to have scheduled tasks based upon the time the server is currently running.
Say at 7pm on Sunday I want a database query to be ran.
The way in which I've considered doing this is to put the task in the script that is ran on each page load in the session init.
Any ideas?
One method to automatically run a PHP script at specified time intervals is to use Crontab. This can be particularly beneficial for scripts that need to automatically update information without user interaction such as a script that gathers website statistics so that they can be emailed to you or a script that regularly retrieves content from another website.
See: PHP CLI and Cron
You can just use cron to trigger your script for you with something like this:
If you have ssh access you can add a crontab entry like this:
crontab -e
and enter something like this:
0 19 * * 0 php -f /path/to/script/file.php
where 19 is the hour (7pm), 0th day of the week (sunday), and 0 is the minute.
this will run at 7pm on sunday.
This is what your cron tab is for. You can specify whatever tasks, scripts, or other programs you need to run at whatever time you want to run them. Cron is run by your operating system and goes by your operating system's clock.
For example if I wanted to run a PHP script every minute, I would put something like the following into my cron tab.
* * * * * php /path/to/script.php
How you actually create cron entries depends on what your server setup is like. If you have some sort of shell access on a Unix/Linux system, you can edit your cron tab easily by running the following command.
crontab -e
That will bring up the crontab in the default text editor.
If you are using something like cPanel, you will have to consult the manual for information on how to edit cron entries.
The actual syntax for the cron can be complicated at first. There are entry generators online that you can use if you need help.
0 * * * * php /some/script.php # This will execute at the 0 minute of every hour.
0 1 * * * php /some/script.php # This will execute at the 0 minute of the first hour of every day. In other words, every day at 1AM.
You should use your systems Cron deamon to schedule and run a PHP file.
First read up on Cron:
https://help.ubuntu.com/community/CronHowto
Then implement this:
Open crontab:
vim crontab -e
Add an entry to your cron table:
0 19 * * 0 /path/to/php /path/to/script.php
Your script.php will contain the code/logic to query the database.
I'm working on a site in php. Is it possible to send cron jobs at times defined by an algorithm? Could I add such a functionally in the console or send it from my php script? I haven't used cron yet.
The first thing that comes to the mind - run a cron job every minute with php script which generates random number in order to check whether to run the rest of the job.
This line in crontab will run cron job every minute (replace paths with yours)
*/1 * * * * /usr/bin/php /path/to/job.php
Or if you can't directly call php, you may use curl or wget like that
*/1 * * * * /usr/bin/curl --silent --compressed http://yoursite.com/job.php
And in your php file do whatever you want to check if it's time to run the rest of the job, like that:
if(rand(1, 60)==1)
{
include 'the_actual_job.php';
}
Set your PHP script to be executed every hour, for example. Then add this code at the top of your script
sleep(rand(1, 60));
Now your script will be executed every hour + some seconds. It is random :)
If you want to schedule a job at a particular time you can use "cron"s friend "at" which will schedule a script a the time requested.
You simply fire off a command like:
$reqtime = '17.00'
system('at -f yourscript.sh ' . $reqtime);
And yourscript.sh will magically run at 17.00 today
I am using Ubuntu server, and I want to do a wget cron job for just about every day of the week for different files.
I have gotten this to work for only one task, but anytime I try to do more it automatically overwrites the old one. I know how to set up times, and the format, etc; but I do not know how to do multiple wget cron jobs.
This is how I've been doing only one so far:
echo "*/10 * * * 5 wget http://XXX.XXX.XXX/files/thursday.php" | crontab -
Can anyone help me? Thanks
best to use the command line crontab function for maintaing cron jobs
crontab -e
will bring up the editor.
The default on most *nix system is vi, which is not newbie friendly, but you can change it to nano or pico with
export EDITOR=nano
and if your on a system like mine, your logged in user may not be the best user to run cron jobs as; so you may may have to use su to switch users before editing the crontab file.
looking at what you are specify doing, unless you really need to go through appache, you can just call the php file like so "php file.php" no wget needed.
*/10 * * * 5 php FULL_PATH/files/thursday.php > /dev/null 2>&1
I have a database with a bunch of links that I want to keep updated. Basically if a link returns a 404 error code I want to remove it from the database. I have a script that I am using however I need to run it manually. How can I make this work using CRON?
in your shell as cron user (or root):
crontab -e
This will bring up your crontab file in your editor. Add a new line something like this:
* */12 * * * /path/to/script
Save/exit the file.
Now for a quick lesson on cronjobs:
-The first 5 arguments in the line tell how often, or when the cron daemon will execute the 6th argument.
-From left-right, arguments represent: minutes, hours, days, weeks, months
-An asterix (*) tells the cron to run on all values of it's associated time measurement (example * * * * * means to run every minute, of every hour, of every week, and of every month!)
In my example, * */12 * * * means to run every 12 hours.
Check out: http://kevin.vanzonneveld.net/techblog/article/schedule_tasks_on_linux_using_crontab/
To run a PHP script with cron you can use the PHP executable and the path to the script.
On most linux systems you want to edit your cron file (the crontab) with the command crontab -e. This will open up a command line based editor and you can just append your new job to the bottom of the file using this format.
<minute> <hour> <day_of_month> <month> <day_of_week> php /path/to/script
If the commands dont work for you let me know what distribution you are using and I can modify the instructions.
/usr/bin/php -q /home/user/public_html/script.php
I have a Linux server and in this I want to execute a cron job for sending birthday mail to all my friend with a PHP program. I want to create a php program that read data from database and send the mail.
I want to know the command of cron job to execute the program on every day automatically. I have no knowledge of Linux commands.
You will want to read up a little bit on the 'crontab' command but basically you will do this.
From a linux command prompt run the crontab command.
Then add this entry:
* * * * * php yourscript/path
You can set what time by modifying the * values. See this URL for information on that:
http://adminschoice.com/crontab-quick-reference
This is the command to add to your crontab file:
0 0 * * * /usr/bin/php /path/to/your/script.php
Adjust the paths to the PHP interpreter and your script as necessary. It will run your script every day at midnight.
This is done using a cron table in unix systems, including linux. Check out some example documentation:
http://en.wikipedia.org/wiki/Cron
http://pubs.opengroup.org/onlinepubs/9699919799/utilities/crontab.html
You'll find many more, if you google for crontab, or if you check out the man crontab pages on your linux box