1

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')");
?>
slayernoah
  • 3,714
  • 10
  • 37
  • 65
PHP_USER1
  • 618
  • 1
  • 13
  • 28

1 Answers1

0

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...

  1. In windows 7, go to your Start Menu type Task Scheduler
  2. Create a Basic Task, just fill up necessary information
  3. Set the trigger, depends on your needs
  4. Select Start a program
  5. Specify the program script, browse the php.exe located at your wamp folder
  6. 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:

  1. Setup a PHP Environment Variable in your Control Panel > System and Security > System > Advance System Settings

  2. Click Environment Variables

  3. In the System Variables select Path and Click Edit

  4. 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.

  5. Restart PC, in your command prompt type php -v

Now you can do this easily:

php -f "C:\WAMP\www\test\index.php"

Darick
  • 451
  • 3
  • 11