Issue
I am using Windows 7 and working with PHP. I am working with a cron job for the first time so I don't know where to start.
After 20 minutes, I want the query to run and insert the value of $i
and after 20 more minutes, I want the value of $i
to be incremented and inserted.
I am currently using the code below:
<?php
include "config.php";
$i=1;
$r=mysql_query("insert into test1(score) values ('$i')");
?>
Solution
In my experience, I'm using window task scheduler, I'm aggregating about 70,000+ records every hour.
First things first, If you are using WAMP make a file named index.php under your test folder
<?php
echo "Hello from Mars";
?>
Next go to your command prompt and try doing this:
C:\WAMP\bin\php\php5.4.1.2\php.exe -f "C:\WAMP\www\test\index.php"
If the output is the same, we are on the right track, moving along...
- In windows 7, go to your Start Menu type Task Scheduler
- Create a Basic Task, just fill up necessary information
- Set the trigger, depends on your needs
- Select Start a program
- Specify the program script, browse the php.exe located at your wamp folder
- Finish
More Information: http://www.howtogeek.com/123393/how-to-automatically-run-programs-and-set-reminders-with-the-windows-task-scheduler/
To identify if your php is running under cli:
<?php
if(PHP_SAPI == 'cli') echo 'Running CLI';
?>
To speed up the process of typing the php location:
Setup a PHP Environment Variable in your Control Panel > System and Security > System > Advance System Settings
Click Environment Variables
In the System Variables select Path and Click Edit
Append the location of your PHP file which is C:\WAMP\bin\php\php5.4.1.2 make sure that you don't forget to include the semicolon which servers to separate the paths.
Restart PC, in your command prompt type php -v
Now you can do this easily:
php -f "C:\WAMP\www\test\index.php"
Answered By - Potato Science