have a php page called cronEmail in the web folder. It incudes the code to end an email to specific users on the website. I want it to open the page once a day and send the email. The page has only php and MySql code to read the recipients of the email.
I am trying to use Task scheduler in the control panel to run the page. I create a user defined script and in schedule I set the time to a certain time and to only run daily once a day.
In the rum command i have tried numerous ways to run it on the time but every time it just passes and does nothing. an example of what I put in for the script is
/web/cronEmail.php OR
chmod 755 /volume1/web/cronEmail.php
There are only two of a many can anyone point me in the right direction
Thanks a million
Seems like you want a cronjob, in the terminal open cron with:
crontab -e
then at the bottom of the file place this
0 4 * * * php /url/to/folder/cronEmail.php
Not sure if you found another solution, but this is what worked for me. If you put the following in the "Run Command" section, it should work:
php /volume1/web/cronEmail.php
You can also create an error log by doing the following:
php /volume1/web/cronEmail.php>> /volume1/web/errors.log 2>&1
If you don't use the php at the beginning, and open up the error.log file that is created, what you'll see is that the Task Scheduler doesn't seem to know that it's looking for PHP, and doesn't recognize the script.
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 am looking for a way to set cron job using PHP. All I would like to do is run a PHP script at a specific time. The user first inputs a time in a script, according to the time specified the server will run the script. I am using windows 7 and xampp.
What I have found is:
Create a php file that calls the cron.php file: Using notepad (or whatever), paste the following into a new file:
$data = file(“http://pearl.supplychain.com/cron.php”);
you’ll need to put it inside the regular php tags, with the “less than sign” ? php at the front, and the ? “greater than sign” at the end. (I can’t seem to just type that because it is “suspicious content” and drupal doesn’t allow it)
Save it as executecron.php, into the same directory as cron.php (htdocs).
Set up a scheduled task that calls this regularly:
Open Start–All Programs–Accessories–System tools–Scheduled tasks.
Double-click on scheduled tasks.
Set up a Daily task that starts at 12:00 am and runs every half hour (or whatever) until 11:59 pm. Tell the task to “run” the following:
C:\cms\xampp\php\php.exe c:\cms\xampp\htdocs\executecron.php
(On this system, php.exe is installed in C:\cms\xampp\php, but you’ll probably have to change the path).
As you can see, to do this, one must Open Start–All Programs–Accessories–System tools–Scheduled tasks.
Can it specific by php code or using another way to do this? Because i want all the work done on php / server instead of need my user config the cron job themselves. Which means i want my php code can set the cron in server and server will look at the cron?
To stefgosselin:
To create the batch file
Open Notepad.
Paste the line "C:\xampp\php\php.exe C:\wamp\www\index.php"
Click "File" -> "Save As"
Ensure "Save as type:" is set to "All Files"
Save the file as "cron.bat" to your C drive
To schedule the batch file to run
Open Command Prompt
Paste the following "schtasks /create /sc minute /mo 20 /tn "PHP Cron Job" /tr C:\cron.bat"
Press Enter
This will make the script run every 20 minutes, the first time 20 minutes from now.
I am able to create a bath file using php, however, are there any way to Paste the following "schtasks /create /sc minute /mo 20 /tn "PHP Cron Job" /tr C:\cron.bat
using php instead of using os? Thank you
Thank you
I found my answer to that question at waytocode.com
They provide 3 possible solutions to run cron jobs on Windows:
Solution-1 using Task scheduler
In your Windows 7/windows 2005/2008.
Go to Startmenu->All Programs->Accessories->System Tools->Task Scheduler->create Task
In the new window:
General (Give the Task name and for testing you can select “Run when User is logged in“)
Trigger (You can Select the running interval as “daily,weekly,monthly”. )
Action (This is most important part. Select a Mozilla firefox as the “program/script” and in the Argument provide the URL to fire with Mozilla firefox).
Solution-2 using Task scheduler and PHP from your XAMPP server
In Windows Xp,no need to copy or install anything(Already PHP is installed on the server like XAMPP)
Goto Task scheduler
Create a task give Running time, then in avanced setting option in the “RUN” command textbox type
C:\xampp\php\php.exe -f c:/xampp/htdocs/waytocode/mycron.php
In Windows 7/server 2005/2008
No need to copy or install anything(Already PHP is installed on the server)
Create a task give Running time in Trigger setting.Then in Action setting option in the “Program/Script” command textbox type
C:\xampp\php\php.exe
and in the “Add arguments (optional)” type
-f c:/xampp/htdocs/mycron.php
Solution–3 install a Windows exe file that will simulate the cron job from *nix system
I don't like to install any exe file to my servers or development machine,
but I'll provide the solution as they posted:
In Windows Xp,Copy all 2 DLL file with wget.exe to the C:\windows folder
Create a task give Running time then in avanced setting option in the “RUN” command textbox type
C:\Windows\wget.exe -q -O NUL http://localhost/mycron.php
In Windows 7/server 2005/2008 ,Copy all 2 DLL file with wget.exe to the C:\windows folder
Create a task give Running time then in avanced setting option in the “Program/Script” command textbox type
C:\Windows\wget.exe
and in the “Add arguments (optional)” type
-q -O NUL http://localhost/mycron.php
Solution-4 using a .bat file and the task scheduler
I found it here at Stackoverflow and it is similar to the first 2:
Create a cron.php file (the code you want to execute at a regular interval)
Create a CRON.BAT file, copy and past the below code in the file
D:\xampp\php\php.exe D:\xampp\htdocs\Application\cron.php
The path I have written is according to my xampp and cron.php file, update the path of files according to your system directory
To schedule a task
Click on start > All Programs > Accessories > System Tools > Scheduled Tasks
Or you can go directly
Control Panel > Scheduled Tasks
Right click in the folder
New > Schedule Task
Give appropriate name to the Task.
In the RUN text field… Type the complete path of the CRON.BAT file
in my case it is
D:\xampp\htdocs\Application\CRON.BAT
Set the schedule of the job, you can use advanced button if required.
Solution-5
I don't like it either because one script can't depend on someone else website but it is a solution anyway.
Use an external online cron job service.
https://www.google.ca/search?q=cron+job+online+service
Chose one solution that it is more appropriate for you. Hope this will help someone.
UPDATE
Solution-6 (Based on the answers below, and works with CodeIgniter too!)
Create the cron.bat file and write the following command and save it.
#ECHO OFF
c:
cd C:\Program Files\Internet Explorer
START iexplore.exe http://localhost/path/to/cron/job/1
Create a task give Running time in Trigger setting.Then in Action setting option in the “Program/Script” command textbox type
C:\xampp\path\htdocs\folder\includes\cron.bat
END UPDATE
Answering your question:
Can it specific by php code or using another way to do this? Because i
want all the work done on php / server instead of need my user config
the cron job themselves. Which means i want my php code can set the
cron in server and server will look at the cron?
There are other ways to do this:
Using cron manager from within PHP
Using cron manager from within PHP
Managing Cron Jobs with PHP
http://code.tutsplus.com/tutorials/managing-cron-jobs-with-php-2--net-19428
Unfortunately, all solutions with PHP needs a *nix server type and / or cPanel and are more or less complicated to implement.
Ok, if I understood correctly, you would like to have a cron job created on a system, without a user having to create the task.
Basically, this can easily be done in a .bat file, (that could even be called from php).
The schtasks app can easily automate the creation of a scheduled task. For example:
schtasks /create /tn UNO /tr YOURAPP.EXE /sc HOURLY /mo 2
See the official MS support page for more info on this nifty application.
Another option that can even be easier for the user is to use an installer. I have not created that many windows apps myself but did have the pleasure of playing with NSIS, and this app also has options to create scheduled tasks, among many many other features way too numerous to name here. Highly recommended if you need a user-installable package.
Hope that helps, happy coding friend.
Another great tool is available for free on Windows, nncron. It uses the exact same syntax than unix' cron:
http://www.nncron.ru/
I find it easier to manage that this horrible schtasks :)
The lite version is the one I would suggest to use. The full powered version supports scripting in the config files. It could be handy but somehow over killed for normal cron jobs.
Steps Create Cron in Windows :
Step 1> Create .bat file
1. open notepad.
2. click File -> Save As.
3.Give the file a name i.e. MyBatchFile.bat Underneath the filename box change the file type to All Files. The .bat on the end of the filename will instruct the PC to open it as a batch file.
Step 2> IN MyBatchFile.bat write following command
ECHO OFF
START File Full Path write here like http://www.google.com
Step 3>
Open Start–All Programs–Accessories–System tools–Scheduled tasks.
Click on create task from right side bar.
name:any one
trigger: set time from drop down and select per day
Action:select .bat file
Click on OK button
Steps Create Cron in Windows OS:
Step 1> Create .bat file
1. Open notepad.
2. Click File -> Save As.
3. Give the file a name i.e. MyBatchFile.bat Underneath the filename box change the file type to All Files. The .bat on the end of the filename will instruct the PC to open it as a batch file.
Step 2> IN MyBatchFile.bat write following command
ECHO OFF
START File Full Path write here like http://www.google.com
Step 3>
Open Start–All Programs–Accessories–System tools–Scheduled tasks.
Click on create task from right side bar.
name:any one
trigger: set time from drop down and select per day
Action:select .bat file
Click on OK button
Another quite simple approach is powershell, to fetch the content of your php-file.
Task-Scheduler, target: Powershell.exe, use arguments:
-Command "(New-Object Net.WebClient).DownloadString('http://myhost/cron/cron.php')"
(Ups, old post)
It is the complete solution I have tried for my own project for windows 10.
1) Go to "start" menu and search for "task scheduler" and open it.
If you are facing any issue of permissions, open it as "run as system administrator".This option is exactly below "open".
And still you are facing issues of permissions contact your system admin.
2) Click on "new task" in right sidebar and a window will be opened.
3) In this window "general" tab will be selected by default. Give a suitable name to task and if require provide short description.
4) Go to "triggers" set here frequency at you want to run it and start date-time, if require expires date-time.and set all require parameters.
5) Got to "Actions" tab. This is the most important part.
In "Program/script", write the absolute path of "php.exe".
In "Start in", write the absolute path of the folder where your intended php file for cron is.
In "Add arguments", write the name of the php file which you want to get run thought the task job.
In "Add arguments", you can also specify the arguments to the files space separated after php file name. and if it has text or special characters, enclose it with double quotes.
If you provide arguments to scripts, you will receive them in $argv[ 1 ], $argv[ 2 ] and so on respectively.
For more details visit: https://medium.com/#shraddha_kulkarni/run-php-cron-in-windows-513fb1aa53a5
I'm working on a wamp development environment and testing how long it takes to get the site indexed. I'm doing this by running cron manually.
The problem is that if there's 700 jobs in the job_queue, each run of cron does only some of them, so I need to run cron several times. How could I keep calling cron in a loop until there are no more jobs left in the job_queue?
Also, I'm open to any drush alternatives. I'm aware of drush cron, but this also does only some of the jobs each run, so needs to be run again manually.
If you want to run something all at once until it's done, cron is the wrong tool for the job; batch API is the tool for that. Unfortunately the search module is written to update only on cron, but there's not a lot of code in search_cron to copy into a batch function. So I'd suggest going the batch route rather wrapping some sort of pseudo-batch around cron, as your end goal doesn't seem to involve cron at all.
step 1. - Run cron every minute
step 2. - Just check if the script is already running. If so - close the "new script"
$lid='';
if(is_array($argv) && isset($argv[1])) {
$lid=$argv[1];
}
if($lid!=='') {
$xx=array();
exec('ps x | grep "thefile.php '.$lid.'" | grep -v "grep"', &$xx);
if(count($xx)>1) {
die('Script '.$lid.' running already... exiting... '."\n");
}
}
Put it in cron with every minute php thefile.php 1
php thefile.php 2
php thefile.php 3 to run 3 scripts at the same time.
drush search-index will generate the remaining search index for you.
I'm running an application where I need to execute the cron job, once a form is submitted,contains more than 1 lac records in a loop(its on-demand execution of cron job and deletes the job once finished).
I'm using php, I tried to configure the job through cpanel as a test and it works...the command was.."/ramdisk/bin/php5 -f /home/user/public_html/domain/cron.php -q", it worked fine.
But when I tried to run the same job with the exec() of php, like I wrote this whole command to a file (I do not know where the original crontab file is located otherwise could have written to it, please suggest a way to find its location) and ran that file like "exec("crontab /home/user/cron/Feed_cron"); ", in this cron is not working...
I doubted whether the crontab command will not work for particular user.. I tried it from the "root" user....which is the root user....tried the command via SSH or Putty and the response was "command not found". Please find a solution for this, also please give me an idea whether my concept works fine...
please suggest a way to find its location
Try
whereis crontab