run a php automatically after every hour - php

I am using a shared windows hosting in which sending 120 mails/hour is allowed though php code.
i have a php page to send emails more than 200 mails at a time.But i want to run the page, after every hour(scheduled task).
I will split the emails(in 100s) and want send automatically after every hour.
How is this possible in php to run a php page after every hour ?
Thanks

Use PHP Cron Jobs with cPanel
cPanel Simple Cron
you can get started with the simple cron tool built into cPanel. The url for it is:
https://www.yoursite.com/page.php
The command to run:
/usr/local/bin/php -f /home/(username)/public_html/page.php
Next you'll want to select an option from all the select boxes. Remember to select an option in each box. If you want something to run every hour, select Minute: 60; Hour:Every; Day: Every; Month: Every; Weekday: Every;
Click save and you are all set! You'll get an email every time the cron job runs, but if you don't want to get it - put :blackhole: into the output email field at the top.

Use a script on Google AppEngine to "ping" yours (Scheduled Tasks to be more precise).
It's free to use.

You can schedule a task in Windows - control panel->administrative tools is where you find task scheduler.

Related

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?

How to write PHP cron jobs without cPanel?

I know we have cron jobs in PHP. but I have a project in development phase and we won't have cPanel access.
We have a PHP + MSSQL application that needs to check the database periodically every 1 minute and collect the data and send a mail to a store admininstrator.
How can we do this?
You can have a alternative of cron jobs solution by implement you function in a file (eg: /very/secret.php if your jobs need to be secure, make sure the function can be call only when it get the right parameter eg: /very/secret.php?key=long-random).
Then use some free cron job server on the web like: https://www.easycron.com/ or https://www.setcronjob.com/ (just do a web search for "free online cron jobs"). You give them your URL and some configuration and then your jobs will be executed by them at a specific time of day.
I understand that you need to run a script to check the database periodically every one minute and collect the data and send a mail to store admin. Also I understand that you have a script and you need to run that script every one minute.
It can be done using "cron job", if you are using Linux server. Or if you are using Windows, there is a way to schedule the task (to run that script every min).
Note: it is nothing to with cPanel. Actually, the cPanel provides a user friendly GUI to schedule the cron job.
But if you are not using panel, you can do it manually.
If you are using Linux, here you can see, how to add the cron job - http://www.cyberciti.biz/faq/how-do-i-add-jobs-to-cron-under-linux-or-unix-oses/
If you are using Windows, here you can see, how to add the cron job - http://windows.microsoft.com/en-us/windows/schedule-task#1TC=windows-7

PHP-send an email at specific time

My system is for reservations, and I want to send a reminder email 15 minutes before without using cron on Linux/Unix/BSD boxen nor Scheduled Tasks on Windows because I'm using mac and the users' PCs will be windows.
So, what should I do?
Initially, I compared all date and time with the ones in the data base but still nothing arrived.
Thanks in advance.
I tried if the date&time now = the date&time in the DB send a conformation email.
and about the corn I have 2 things:
1- I'm using mac -as a programmer- and if I want to implement this function I'll have to use Scheduled Tasks on Windows which - as I think- will be need working on a windows environment.
and the system will be installed on a Microsoft PC.
2- I have not dealt with corns before, and I'm afraid it'll take time that I don't have.
You have to use some kind of service or job to trigger the email to be send. Because php is self needs to know when to exec the code ("script").
Use CRON or Task Scheduler or build your own job / Service
For Scheduling jobs on linux you can you at command. Here is example
at 12:32 -m -f /usr/local/bin/backup-script
Here is good manual for at linux.
http://www.brunolinux.com/02-The_Terminal/The_at_Command.html
If you want to avoid cron job, then you have to depend on some hacky solution to trigger/call your "send email" code
like,
depend on site users. If they are coming on regular intervals every minute, check on each reservation the upcoming reservation time and email to them.
run a daemon process OR a function that keeps running for a specific period of time, say 24 hours, and check for upcoming reservations every minute or xyz time. You can put this process on sleep for a minute (or more) to check reservations on regular intervals.
use 3rd party cronjob scripts or hosted cronjobs. like https://www.setcronjob.com/ (needs $ for this solution) or onlinecrontab.com

How to send emails via cron job usng PHP mysql

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.

how to trigger a function on defined date

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.

Categories